mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 10:00:17 -04:00
30 lines
687 B
JavaScript
30 lines
687 B
JavaScript
// eslint-disable-next-line import/prefer-default-export
|
|
export class ErrorHandler {
|
|
constructor() {
|
|
this.logToConsole = true;
|
|
this.reset();
|
|
}
|
|
|
|
reset() {
|
|
this.error = null;
|
|
}
|
|
|
|
process(error) {
|
|
this.reset();
|
|
if (!(error instanceof Error)) {
|
|
if (error.status && error.data) {
|
|
// $q rejection
|
|
switch (error.status) {
|
|
case 403: error = new Error('You have no permissions to view this page.'); break;
|
|
default: error = new Error(error.data.message); break;
|
|
}
|
|
}
|
|
this.error = error;
|
|
}
|
|
if (this.logToConsole) {
|
|
// eslint-disable-next-line no-console
|
|
console.error(error);
|
|
}
|
|
}
|
|
}
|