8000 chore!: Rename `Status` and `XyzError` to `HttpStatus` and `XyzHttpEr… · aklinker1/zeta@8c50436 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c50436

Browse files
committed
chore!: Rename Status and XyzError to HttpStatus and XyzHttpError
1 parent 69ba98a commit 8c50436

11 files changed

Lines changed: 247 additions & 233 deletions

File tree

‎README.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,16 @@ const app = createApp().get(
271271
When defining multiple schemas for different status codes, instead of returning the value directly, you'll need to return the value of the `status` function:
272272

273273
```ts
274-
import { ErrorResponse, createApp, Status } from "@aklinker1/zeta";
275-
import { NotFoundError } from "@aklinker1/zeta/errors";
274+
import { ErrorResponse, createApp, HttpStatus } from "@aklinker1/zeta";
275+
import { NotFoundHttpError } from "@aklinker1/zeta/errors";
276276

277277
const app = createApp().post(
278278
"/api/users",
279279
{
280280
body: UserSchema,
281281
responses: {
282-
[Status.Created]: User,
283-
[Status.Conflict]: ErrorResponse,
282+
[HttpStatus.Created]: User,
283+
[HttpStatus.Conflict]: ErrorResponse,
284284
},
285285
},
286286
async ({ status, body }) => {
@@ -290,14 +290,14 @@ const app = createApp().post(
290290
// Zeta maps the HttpError's status code to the correct response schema.
291291
if (userExists) {
292292
throw new HttpError(
293-
Status.Conflict,
293+
HttpStatus.Conflict,
294294
"A user with this email already exists.",
295295
);
296296
}
297297

298298
const newUser = await db.createUser(body);
299299

300-
return status(Status.Created, newUser);
300+
return status(HttpStatus.Created, newUser);
301301
},
302302
);
303303
```
@@ -393,7 +393,7 @@ Here's an example combining several different hooks:
393393

394394
```ts
395395
import { createApp } from "@aklinker1/zeta";
396-
import { NotFoundError } from "@aklinker1/zeta/errors";
396+
import { NotFoundHttpError } from "@aklinker1/zeta/errors";
397397

398398
const usersApp = createApp({ prefix: "/api/users" })
399399
.get("/", {}, () => {
@@ -409,7 +409,7 @@ const usersApp = createApp({ prefix: "/api/users" })
409409
})
410410
.onBeforeHandle(async ({ path }) => {
411411
const user = await getUser(path.userId);
412-
if (user == null) throw new NotFoundError("User not found");
412+
if (user == null) throw new NotFoundHttpError("User not found");
413413

414414
return { user };
415415
})
@@ -619,10 +619,10 @@ By default, Zeta provides built-in error handling. It also provides useful error
619619

620620
```ts
621621
import { HttpError } from "@aklinker1/zeta/errors";
622-
import { Status } from "@aklinker1/zeta/status";
622+
import { HttpStatus } from "@aklinker1/zeta/status";
623623

624624
const app = createApp().get("/users", {}, () => {
625-
throw new HttpError(Status.NotImplemented, "TODO");
625+
throw new HttpError(HttpStatus.NotImplemented, "TODO");
626626
});
627627
```
628628

@@ -657,12 +657,12 @@ const app = createApp()
657657

658658
When a non-`HttpError` value is thrown, Zeta returns a `500 Internal Server Error` with the original error as the `cause`.
659659

660-
## Status Codes
660+
## HttpStatus Codes
661661

662662
Zeta provides an enum of all HTTP status codes. You should use this instead of literal values.
663663

664664
```diff
665-
import { Status } from "@aklinker1/zeta/status";
665+
import { HttpStatus } from "@aklinker1/zeta/status";
666666

667667
const app = createApp()
668668
.post(
@@ -671,7 +671,7 @@ const app = createApp()
671671
({ set }) => {
672672
// ...
673673
- set.status = 201;
674-
+ set.status = Status.Created;
674+
+ set.status = HttpStatus.Created;
675675
},
676676
);
677677
```
@@ -746,7 +746,7 @@ expect(response).toEqual([...]);
746746
await expect(
747747
() => client.fetch("GET", "/users/123", {})
748748
).rejects.toEqual({
749-
status: Status.NotFound,
749+
status: HttpStatus.NotFound,
750750
message: "User not found",
751751
})
752752
```

‎example.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createApp } from "./src";
22
import { version } from "./package.json" with { type: "json" };
33
import { z } from "zod/v4";
4-
import { NotFoundError } from "./src/errors";
4+
import { NotFoundHttpError } from "./src/errors";
55
import { zodSchemaAdapter } from "./src/adapters/zod-schema-adapter";
6-
import { Status } from "./src/status";
6+
import { HttpStatus } from "./src/status";
77
import { ErrorResponse } from "./src/error-response";
88

99
const Entry = z.object({
@@ -74,7 +74,7 @@ const app = createApp({
7474
},
7575
({ body, set }) => {
7676
entries.push(body);
77-
set.status = Status.Accepted;
77+
set.status = HttpStatus.Accepted;
7878
},
7979
)
8080
.get(
@@ -86,15 +86,16 @@ const app = createApp({
8686
tags: ["Entries"],
8787
params: z.object({ id: z.coerce.number() }),
8888
responses: {
89-
[Status.Ok]: Entry,
90-
[Status.NotFound]: ErrorResponse,
89+
[HttpStatus.Ok]: Entry,
90+
[HttpStatus.NotFound]: ErrorResponse,
9191
},
9292
},
9393
({ params, status }) => {
9494
const entry = entries.find((entry) => entry.id === params.id);
95-
if (!entry) throw new NotFoundError(undefined, { entryId: params.id });
95+
if (!entry)
96+
throw new NotFoundHttpError(undefined, { entryId: params.id });
9697

97-
return status(Status.Ok, entry);
98+
return status(HttpStatus.Ok, entry);
9899
},
99100
)
100101
.get(

‎jsr.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"exports": {
1111
".": "./src/index.ts",
1212
"./types": "./src/types.ts",
13-
"./errors": "./src/errors.ts",
1413
"./client": "./src/client.ts",
1514
"./testing": "./src/testing.ts",
1615
"./adapters/zod-schema-adapter": "./src/adapters/zod-schema-adapter.ts"

‎src/app.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { callHandler } from "./internal/call-handler";
22
import { HttpError } from "./errors";
3-
import { Status } from "./status";
3+
import { HttpStatus } from "./status";
44
import type {
55
App,
66
RouterData,
@@ -147,7 +147,7 @@ export function createApp<TPrefix extends BasePrefix = "">(
147147
request,
148148
method: request.method,
149149
set: {
150-
status: Status.Ok,
150+
status: HttpStatus.Ok,
151151
headers: {},
152152
},
153153
} satisfies OnGlobalRequestContext;
@@ -175,7 +175,9 @@ export function createApp<TPrefix extends BasePrefix = "">(
175175
}
176176

177177
const status =
178-
err instanceof HttpError ? err.status : Status.InternalServerError;
178+
err instanceof HttpError
179+
? err.status
180+
: HttpStatus.InternalServerError;
179181
const res = Response.json(serializeErrorResponse(err), { status });
180182
ctx.response = res;
181183
return res;

‎src/error-response.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { StandardSchemaV1 } from "@standard-schema/spec";
2-
import type { Status } from "./status";
2+
import type { HttpStatus } from "./status";
33

44
/**
55
* A schema for a error response. Use when defining additional status codes that an operation might return with:
@@ -69,7 +69,7 @@ export type ErrorResponse = {
6969
[additionalInfo: string]: any;
7070
name: string;
7171
message: string;
72-
status: Status;
72+
status: HttpStatus;
7373
stack?: string[];
7474
cause?: ErrorResponse;
7575
};

0 commit comments

Comments
 (0)
0