Expose custom error property #836
-
Hi elysians 👋 I skimmed through the docs trying to find a way to expose a property of my custom class BaseError extends Error {
readonly extensions: { [key: string]: string };
constructor(message: string, code: string) {
super(message);
this.extensions = { code };
}
}
export enum CustomErrorCodes {
SIGN_IN_REQUIRED = 'You are not signed in.',
}
type CustomErrorCode = keyof typeof CustomErrorCodes;
export class CustomError extends BaseError {
public constructor(public code: CustomErrorCode) {
super(CustomErrorCodes[code], code);
}
} When I then throw this error eg in a .get('/test') => {
throw new CustomError('SIGN_IN_REQUIRED');
}) I only get the {"name":"Error","message":"You are not signed in."} Is there an easy way to also expose the {"name":"Error","message":"You are not signed in.","extensions":{"code":"SIGN_IN_REQUIRED"}} |
Beta Was this translation helpful? Give feedback.
Answered by
kravetsone
Sep 19, 2024
Replies: 1 comment 5 replies
-
you can do everything what u want with onError hook |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://elysiajs.com/essential/life-cycle.html#custom-error