fennec-be/src/commons/exceptions/application.exception.ts

26 lines
595 B
TypeScript

import { pick } from 'ramda';
export class ApplicationException extends Error {
code: number;
error: Error;
constructor(
message: string | { error?: Error; message?: string | any; code?: number },
) {
if (message instanceof Object) {
super();
this.code = message.code;
this.error = message.error;
this.message = message.message as any;
} else if (typeof message === 'string') {
super((message as unknown) as any);
} else {
super((message as unknown) as any);
}
}
toJSON() {
return pick(['code', 'message'], this);
}
}