Skip to content

ErrorHandlerBase

class ErrorHandlerBase extends FlareBase

Base class for HTTP error handlers registered on HttpArc.error.

Return a ResponseLike from ErrorHandlerBase.handle to send a custom response; return void (or omit a return) to let the error propagate to the next handler or default path.

new ErrorHandlerBase()

new ErrorHandlerBase(): ErrorHandlerBase
config: readonly ConfigToken<unknown>[]

Declares the config tokens this class requires.

Parallel to static deps. When declared, this.config(token) validates that the token is in this array before resolving, identical to how this.inject(token) validates static deps.

deps: ServiceToken<FlareService>[]

Declares the service tokens this class is allowed to inject().

Tokens not listed here cause inject() to throw at the call site, naming both the class and the offending token.

config<T>(token: ConfigToken<T>): T

Resolves a typed config section by token.

Mirrors inject() + static deps: the class must declare a static config array, and the requested token must appear in it. Both checks throw a developer-facing error when violated.

token ConfigToken<T>

returns T

Example:

class DbService extends FlareService {
static config = [DbConfig];
async onStart() {
const { url } = this.config(DbConfig);
}
}

Throws:

When the class has no static config declaration.

Throws:

When the token is not present in static config.

handle(err: FlareError<undefined> | Error, context: HttpErrorContext): void | ResponseLike | Promise<void | ResponseLike>

Handles an error raised during the HTTP pipeline for the current request.

err FlareError<undefined> | Error

context HttpErrorContext

returns void | ResponseLike | Promise<void | ResponseLike> A response to short-circuit error handling, or void to defer to other handlers.

inject<T extends FlareService>(token: ServiceToken<T>): Injected<T>

Resolves a dependency declared on static deps, returning the service with framework members hidden from its static type.

token ServiceToken<T>

returns Injected<T>

Throws:

When the token is not present in this class’s static deps array.

Learn: ErrorHandlerBase classes

Last updated: