You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 69ba98a
Browse filesBrowse the repository at this point in the historyBrowse files
Breaking changes:
- When defining an endpoint, `response` was renamed to `responses`
- `onGlobalError` no longer supports a return type. Zeta converts all errors into responses automatically
- Fix typo in type name: `OnGlobalErrorHoos` → `OnGlobalErrorHooks`
- `@aklinker1/zeta/status` is merged into `@aklinker1/zeta`
When a response schema is defined, the return value from the function is type-safe. If you want to return a custom status code or headers, you can do so with the `set` function provided by the context:
271
+
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:
// For error responses, throwing is the recommended approach.
290
+
// Zeta maps the HttpError's status code to the correct response schema.
291
+
if (userExists) {
292
+
thrownewHttpError(
293
+
Status.Conflict,
294
+
"A user with this email already exists.",
295
+
);
296
+
}
297
+
298
+
const newUser =awaitdb.createUser(body);
299
+
300
+
returnstatus(Status.Created, newUser);
301
+
},
302
+
);
276
303
```
277
304
278
-
> As of right now, you can't add custom status codes to the OpenAPI docs or as apart of the response schema. The OpenAPI spec will always show `200 OK` as the response.
305
+
> When defining custom error responses, use `ErrorResponse` schema from `@aklinker1/zeta`.
306
+
307
+
When a response schema(s) are defined, the return value from the function is type-safe.
308
+
309
+
#### Custom Content Types
279
310
280
-
By default, Zeta will show`application/json` as the content type in the OpenAPI docs. you can override this by setting the `contentType` metadata on your schema:
311
+
By default, Zeta will use`application/json` as the content type in the OpenAPI docs. you can override this by setting the `contentType` metadata on your schema:
You can use any of the following APIs to hook into the request lifecycle:
@@ -327,7 +382,7 @@ graph LR
327
382
- If a `Response` value is not returned, Zeta infers the response content type based on the handler's response value.
328
383
-`onGlobalAfterResponse`: Called after the response is sent to the client.
329
384
- Return value is ignored.
330
-
-`onGlobalError`: If an error is thrown at any point in the lifecycle (other than `onGlobalAfterResponse`), this hook will be called giving you the opportunity to report the error or change the response format by optionally returning a `Response` object.
385
+
-`onGlobalError`: If an error is thrown at any point in the lifecycle, this hook will be called giving you the opportunity to report the error.
331
386
332
387
There are two types of hooks: global and isolated.
0 commit comments