RED-7558: backport generic error handling.
This commit is contained in:
parent
cbd0d5ce26
commit
25b456ae8e
@ -1,10 +1,28 @@
|
||||
import { ErrorHandler, Injectable } from '@angular/core';
|
||||
import { ErrorHandler, Inject, Injectable, Injector } from '@angular/core';
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
import { Toaster } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
|
||||
@Injectable()
|
||||
export class GlobalErrorHandler extends ErrorHandler {
|
||||
constructor(@Inject(Injector) private _injector: Injector) {
|
||||
super();
|
||||
}
|
||||
handleError(error: Error): void {
|
||||
const chunkFailedMessage = /Loading chunk [\d]+ failed/;
|
||||
console.write(error);
|
||||
if (error.message.includes('HttpErrorResponse')) {
|
||||
const err = JSON.parse(error.message.split('HttpErrorResponse:')[1]) as HttpErrorResponse;
|
||||
if (err.status >= HttpStatusCode.BadRequest && err.status <= HttpStatusCode.InternalServerError) {
|
||||
const toaster = this._injector.get(Toaster);
|
||||
if (err.error.message) {
|
||||
toaster.rawError(err.error.message);
|
||||
} else if ([400, 403, 404, 409, 500].includes(err.status)) {
|
||||
toaster.rawError(_(`generic-errors.${err.status}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error?.message?.includes('An error happened during access validation')) {
|
||||
console.log('User is not authorized to access this page');
|
||||
}
|
||||
|
||||
@ -2284,5 +2284,12 @@
|
||||
"select": "Wählen"
|
||||
}
|
||||
},
|
||||
"yesterday": "Gestern"
|
||||
"yesterday": "Gestern",
|
||||
"generic-errors": {
|
||||
"400": "",
|
||||
"403": "",
|
||||
"404": "",
|
||||
"409": "",
|
||||
"500": ""
|
||||
}
|
||||
}
|
||||
|
||||
@ -2306,5 +2306,12 @@
|
||||
"select": "Select"
|
||||
}
|
||||
},
|
||||
"yesterday": "Yesterday"
|
||||
"yesterday": "Yesterday",
|
||||
"generic-errors": {
|
||||
"400": "The sent request is not valid.",
|
||||
"403": "Access to the requested resource is not allowed.",
|
||||
"404": "The requested resource could not be found.",
|
||||
"409": "The request is incompatible with the current state.",
|
||||
"500": "The server encountered an unexpected condition that prevented it from fulfilling the request."
|
||||
}
|
||||
}
|
||||
|
||||
@ -2273,5 +2273,12 @@
|
||||
"select": "Wählen"
|
||||
}
|
||||
},
|
||||
"yesterday": "Gestern"
|
||||
"yesterday": "Gestern",
|
||||
"generic-errors": {
|
||||
"400": "",
|
||||
"403": "",
|
||||
"404": "",
|
||||
"409": "",
|
||||
"500": ""
|
||||
}
|
||||
}
|
||||
|
||||
@ -2295,5 +2295,12 @@
|
||||
"select": "Select"
|
||||
}
|
||||
},
|
||||
"yesterday": "Yesterday"
|
||||
"yesterday": "Yesterday",
|
||||
"generic-errors": {
|
||||
"400": "The sent request is not valid.",
|
||||
"403": "Access to the requested resource is not allowed.",
|
||||
"404": "The requested resource could not be found.",
|
||||
"409": "The request is incompatible with the current state.",
|
||||
"500": "The server encountered an unexpected condition that prevented it from fulfilling the request."
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 7312caa8d0119c5c153f02ddc22075ec9e945451
|
||||
Subproject commit d6f712232942f41a47d652cfb6dabc9d6b1694c7
|
||||
Loading…
x
Reference in New Issue
Block a user