2019-04-12 11:43:22 -05:00
|
|
|
type E = { message: string, code: string, id: string, kind?: 'client' | 'server', httpStatusCode?: number };
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
export class ApiError extends Error {
|
|
|
|
public message: string;
|
|
|
|
public code: string;
|
|
|
|
public id: string;
|
|
|
|
public kind: string;
|
2019-02-22 20:20:58 -06:00
|
|
|
public httpStatusCode?: number;
|
2019-02-21 20:46:58 -06:00
|
|
|
public info?: any;
|
|
|
|
|
2019-04-12 11:43:22 -05:00
|
|
|
constructor(e?: E | null | undefined, info?: any | null | undefined) {
|
2019-02-21 20:46:58 -06:00
|
|
|
if (e == null) e = {
|
|
|
|
message: 'Internal error occurred. Please contact us if the error persists.',
|
|
|
|
code: 'INTERNAL_ERROR',
|
|
|
|
id: '5d37dbcb-891e-41ca-a3d6-e690c97775ac',
|
2019-02-22 20:20:58 -06:00
|
|
|
kind: 'server',
|
|
|
|
httpStatusCode: 500
|
2019-02-21 20:46:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
super(e.message);
|
|
|
|
this.message = e.message;
|
|
|
|
this.code = e.code;
|
|
|
|
this.id = e.id;
|
|
|
|
this.kind = e.kind || 'client';
|
2019-02-22 20:20:58 -06:00
|
|
|
this.httpStatusCode = e.httpStatusCode;
|
2019-02-21 20:46:58 -06:00
|
|
|
this.info = info;
|
|
|
|
}
|
|
|
|
}
|