Inline error handlers
Register function error handlers with host.http.error and optional named inject maps.
AI generated, pending review
Register function handlers on host.http.error or g.error inside a route group.
Overloads
Section titled “Overloads”| Overload | Signature |
|---|---|
| Function | .error(HttpErrorHandler) |
| Function + options | .error(HttpErrorHandlerOptions, HttpErrorHandler) |
import { FlareError, FlareHost, FlareResponse } from "@flare-ts/core";import { flareErrorCodes } from "@flare-ts/core/errors";import { node } from "@flare-ts/core/node";
const UserErrors = flareErrorCodes({ not_found: { UserNotFound: { expose: true, code: 1001 }, },});
const host = new FlareHost(node);
host.http.error((err, context) => { if (err instanceof FlareError && err.category === "not_found") { return new FlareResponse(404, { error: err.name, requestId: context.requestId, }); }});
host.http.get("/users/missing", () => { throw new FlareError(UserErrors.not_found.UserNotFound);});
const app = host.build();app.run();Handler signature
Section titled “Handler signature”(err, context, scope) => ResponseLike | void | Promise<...>| Argument | Type | Notes |
|---|---|---|
err | FlareError | Error | The thrown value |
context | HttpErrorContext | requestId, method, url, optional stage / target |
scope | HandlerScope | inject map entries and scope.config |
There is no ctx.state on error handlers. Pass data through FlareError.detail or an injected service.
HttpErrorHandlerOptions
Section titled “HttpErrorHandlerOptions”| Option | Purpose |
|---|---|
inject | Named map { name: Token } for scope.name |
name | Display name for the generated wrapper |
import { FlareHost, FlareResponse, Logger } from "@flare-ts/core";import { node } from "@flare-ts/core/node";
const host = new FlareHost(node);
host.http.error({ inject: { log: Logger } }, (err, context, scope) => { scope.log.error(err, "unhandled", { requestId: context.requestId }); return new FlareResponse(500, { error: "Internal Server Error" });});
const app = host.build();app.run();