RenaiApp/src/types/error.ts

20 lines
481 B
TypeScript
Raw Normal View History

2019-06-30 01:18:21 +02:00
export const enum Errors {
ERROR = 'ERROR',
ENOLOGIN = 'ENOLOGIN',
ELOGINFAIL = 'ELOGINFAIL',
EINITFAIL = 'EINITFAIL',
2019-06-30 01:18:21 +02:00
}
const messages = {
[Errors.ERROR]: 'generic error',
2019-06-30 01:18:21 +02:00
[Errors.ENOLOGIN]: 'no login form found',
[Errors.ELOGINFAIL]: 'login failed',
[Errors.EINITFAIL]: 'initialization failed',
2019-06-30 01:18:21 +02:00
};
export class RenaiError extends Error {
2019-06-30 01:18:21 +02:00
constructor(eno: Errors = Errors.ERROR, msg: string = '') {
super(`${messages[eno]}.${msg ? ` ${msg}` : ''}`);
2019-06-30 01:18:21 +02:00
}
}