Skip to content

Commit 30b1c46

Browse files
committed
chore: add pre-commit hooks for lint and update readme
1 parent ca90a57 commit 30b1c46

5 files changed

Lines changed: 56 additions & 13 deletions

File tree

.githooks/pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Running lint..."
5+
npm run lint
6+
7+
echo "Running format check..."
8+
npm run format:check
9+
10+
echo "Running typecheck..."
11+
npm run typecheck
12+
13+
echo "Running tests..."
14+
npm test
15+
16+
echo "All checks passed."

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ try {
100100

101101
All exceptions inherit from `RdapApiError` and include `statusCode`, `error`, and `message` properties.
102102

103-
| Exception | HTTP Status | When |
104-
| --------------------------- | ----------- | ---------------------------- |
105-
| `ValidationError` | 400 | Invalid input format |
106-
| `AuthenticationError` | 401 | Missing or invalid API key |
107-
| `SubscriptionRequiredError` | 403 | No active subscription |
108-
| `NotFoundError` | 404 | No RDAP data found |
109-
| `RateLimitError` | 429 | Rate limit or quota exceeded |
110-
| `UpstreamError` | 502 | Upstream RDAP server error |
103+
| Exception | HTTP Status | When |
104+
| ----------------------------- | ----------- | ----------------------------------- |
105+
| `ValidationError` | 400 | Invalid input format |
106+
| `AuthenticationError` | 401 | Missing or invalid API key |
107+
| `SubscriptionRequiredError` | 403 | No active subscription |
108+
| `NotFoundError` | 404 | No RDAP data found |
109+
| `RateLimitError` | 429 | Rate limit or quota exceeded |
110+
| `UpstreamError` | 502 | Upstream RDAP server error |
111+
| `TemporarilyUnavailableError` | 503 | Domain data temporarily unavailable |
111112

112113
## Configuration
113114

@@ -138,6 +139,14 @@ import type { DomainResponse, IpResponse, AsnResponse } from "rdapapi";
138139
- [OpenAPI Spec](https://rdapapi.io/openapi.yaml)
139140
- [Pricing](https://rdapapi.io/pricing)
140141

142+
## Development
143+
144+
Set up pre-commit hooks (runs lint + tests before each commit):
145+
146+
```bash
147+
git config core.hooksPath .githooks
148+
```
149+
141150
## License
142151

143152
MIT

src/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ export class RdapClient {
104104

105105
if (response.status === 503) {
106106
const retryAfter = response.headers.get("Retry-After");
107-
throw new TemporarilyUnavailableError(message, error, retryAfter ? parseInt(retryAfter, 10) : null);
107+
throw new TemporarilyUnavailableError(
108+
message,
109+
error,
110+
retryAfter ? parseInt(retryAfter, 10) : null,
111+
);
108112
}
109113

110114
const ErrorClass = ERROR_MAP[response.status];

tests/client.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ describe("error handling", () => {
338338
it("throws TemporarilyUnavailableError on 503 with retryAfter", async () => {
339339
const client = new RdapClient("test-key", { baseUrl: BASE_URL });
340340
globalThis.fetch = mockFetch(
341-
{ error: "temporarily_unavailable", message: "Data for this domain is temporarily unavailable." },
341+
{
342+
error: "temporarily_unavailable",
343+
message: "Data for this domain is temporarily unavailable.",
344+
},
342345
503,
343346
{ "Retry-After": "300" },
344347
);
@@ -356,7 +359,10 @@ describe("error handling", () => {
356359
it("throws TemporarilyUnavailableError with null retryAfter when header missing", async () => {
357360
const client = new RdapClient("test-key", { baseUrl: BASE_URL });
358361
globalThis.fetch = mockFetch(
359-
{ error: "temporarily_unavailable", message: "Data for this domain is temporarily unavailable." },
362+
{
363+
error: "temporarily_unavailable",
364+
message: "Data for this domain is temporarily unavailable.",
365+
},
360366
503,
361367
);
362368

tests/errors.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ describe("RateLimitError", () => {
8585

8686
describe("TemporarilyUnavailableError", () => {
8787
it("has status 503, retryAfter, and correct prototype chain", () => {
88-
const err = new TemporarilyUnavailableError("Temporarily unavailable", "temporarily_unavailable", 300);
88+
const err = new TemporarilyUnavailableError(
89+
"Temporarily unavailable",
90+
"temporarily_unavailable",
91+
300,
92+
);
8993
expect(err.statusCode).toBe(503);
9094
expect(err.retryAfter).toBe(300);
9195
expect(err.name).toBe("TemporarilyUnavailableError");
@@ -94,7 +98,11 @@ describe("TemporarilyUnavailableError", () => {
9498
});
9599

96100
it("handles null retryAfter", () => {
97-
const err = new TemporarilyUnavailableError("Temporarily unavailable", "temporarily_unavailable", null);
101+
const err = new TemporarilyUnavailableError(
102+
"Temporarily unavailable",
103+
"temporarily_unavailable",
104+
null,
105+
);
98106
expect(err.retryAfter).toBeNull();
99107
});
100108
});

0 commit comments

Comments
 (0)