accounts-frontend/packages/app/services/request/InternalServerError.ts

32 lines
816 B
TypeScript
Raw Normal View History

2019-12-07 13:28:52 +02:00
import { Resp } from './request';
export default class InternalServerError extends Error {
2020-05-24 02:08:24 +03:00
public readonly error: Error | Record<string, any>;
public readonly originalResponse: Resp<any>;
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
constructor(error: Error | string | Record<string, any>, resp?: Response | Record<string, any>) {
super();
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
error = error || 'no error message';
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
this.name = this.constructor.name;
this.message = this.constructor.name;
this.stack = new Error().stack;
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
if (resp) {
this.originalResponse = resp;
}
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
if (typeof error === 'string') {
error = new Error(error);
}
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
if ('message' in error) {
this.message = error.message;
}
2019-12-07 13:28:52 +02:00
2020-05-24 02:08:24 +03:00
this.error = error;
Object.assign(this, error);
}
2019-12-07 13:28:52 +02:00
}