Skip to content

Variable: OnError

ts
const OnError: (options?) => MethodDecorator;

Defined in: packages/core/src/decorators/lifecycle.decorators.ts:207

Hook called when error occurs

Parameters

ParameterTypeDescription
options?{ before?: boolean; }-
options.before?booleanInsert before other hooks

Returns

MethodDecorator

See

https://elysiajs.com/essential/life-cycle.html#on-error

Example

typescript
@Controller('/users')
export class UserController {
  @OnError()
  async handleError({ error, set }: Context) {
    console.error('Error occurred:', error);
    set.status = 500;
    return { error: 'Internal Server Error' };
  }
}

Released under the MIT License.