Merge branch 'RED-6893' into 'master'

RED-6893: Handled generic errors.

See merge request redactmanager/red-ui!153
This commit is contained in:
Dan Percic 2023-10-20 14:39:35 +02:00
commit 6da45310e8
6 changed files with 52 additions and 6 deletions

View File

@ -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');
}

View File

@ -2540,5 +2540,12 @@
"select": "Wählen"
}
},
"yesterday": "Gestern"
"yesterday": "Gestern",
"generic-errors": {
"400": "",
"403": "",
"404": "",
"409": "",
"500": ""
}
}

View File

@ -2545,5 +2545,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."
}
}

View File

@ -2545,5 +2545,12 @@
"select": "Wählen"
}
},
"yesterday": "Gestern"
"yesterday": "Gestern",
"generic-errors": {
"400": "",
"403": "",
"404": "",
"409": "",
"500": ""
}
}

View File

@ -2545,5 +2545,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 bfaae5adf6522a099a55c7f3546dee3b542c4c33
Subproject commit a6383c1dbc840115897a31567c3f5633ba78b43a