forked from UnlyEd/universal-language-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.ts
36 lines (32 loc) · 916 Bytes
/
error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export enum ERROR_LEVELS {
ERROR = 'error',
WARNING = 'warning',
}
export const LEVEL_ERROR = ERROR_LEVELS.ERROR;
export const LEVEL_WARNING = ERROR_LEVELS.WARNING;
export declare type ErrorHandler = (
error: Error,
level: ERROR_LEVELS,
origin: string, // Origin of the error (function's name)
context?: object, // Additional data context to help further debug
) => void;
/**
* Default error handler
* Doesn't do anything but log the error to the console
*
* @param error
* @param level
* @private
*/
export const _defaultErrorHandler: ErrorHandler = (error: Error, level: ERROR_LEVELS): void => {
if (level === LEVEL_ERROR) {
// eslint-disable-next-line no-console
console.error(error);
} else if (level === LEVEL_WARNING) {
// eslint-disable-next-line no-console
console.warn(error);
} else {
// eslint-disable-next-line no-console
console.error(error);
}
};