Merge pull request #4755 from FinnStutzenstein/clientErrorHandling

Client error handling
This commit is contained in:
Finn Stutzenstein 2019-08-06 15:22:16 +02:00 committed by GitHub
commit a804f26162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -58,10 +58,15 @@ export abstract class BaseViewComponent extends BaseComponent implements OnDestr
* Opens an error snack bar with the given error message.
* This is implemented as an arrow function to capture the called `this`. You can use this function
* as callback (`.then(..., this.raiseError)`) instead of doing `this.raiseError.bind(this)`.
* @param message The message to show.
*
* @param message The message to show or an "real" error, which will be passed to the console.
*/
protected raiseError = (message: string): void => {
this.messageSnackBar = this.matSnackBar.open(message, this.translate.instant('OK'), {
protected raiseError = (message: string | Error): void => {
if (message instanceof Error) {
console.error(message);
message = this.translate.instant('A client error occured. Please contact your system administrator.');
}
this.messageSnackBar = this.matSnackBar.open(message as string, this.translate.instant('OK'), {
duration: 0
});
};