yacd/src/misc/errors.ts

29 lines
679 B
TypeScript
Raw Normal View History

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);
}
}
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.',
},
default: {
2020-10-31 18:18:04 +08:00
message: 'Oops, something went wrong!',
},
};
2020-10-31 18:18:04 +08:00
export type Err = { code: number };
export function deriveMessageFromError(err: Err) {
const { code } = err;
if (typeof code === 'number') {
return errors[code];
}
return errors.default;
}