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