2019-05-14 00:30:36 +08:00
|
|
|
export const DOES_NOT_SUPPORT_FETCH = 0;
|
|
|
|
|
2022-06-05 23:40:25 +08:00
|
|
|
export class YacdError extends Error {
|
|
|
|
constructor(public message: string, public code?: string | number) {
|
|
|
|
super(message);
|
|
|
|
Error.captureStackTrace(this, this.constructor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 00:30:36 +08:00
|
|
|
export const errors = {
|
|
|
|
[DOES_NOT_SUPPORT_FETCH]: {
|
|
|
|
message: 'Browser not supported!',
|
2020-10-31 18:18:04 +08:00
|
|
|
detail: 'This browser does not support "fetch", please choose another one.',
|
2019-05-14 00:30:36 +08:00
|
|
|
},
|
|
|
|
default: {
|
2020-10-31 18:18:04 +08:00
|
|
|
message: 'Oops, something went wrong!',
|
|
|
|
},
|
2019-05-14 00:30:36 +08:00
|
|
|
};
|
|
|
|
|
2020-10-31 18:18:04 +08:00
|
|
|
export type Err = { code: number };
|
|
|
|
|
|
|
|
export function deriveMessageFromError(err: Err) {
|
2019-05-14 00:30:36 +08:00
|
|
|
const { code } = err;
|
|
|
|
if (typeof code === 'number') {
|
|
|
|
return errors[code];
|
|
|
|
}
|
|
|
|
return errors.default;
|
|
|
|
}
|