From 7ad1bb01e9d03a98af795635de374d2626023b38 Mon Sep 17 00:00:00 2001 From: FlayInAHook Date: Fri, 4 Dec 2020 16:32:29 +0100 Subject: [PATCH] beautified error handling --- src/app/graphql.module.ts | 3 ++- src/app/helperFunctions/replaceAll.ts | 3 +++ src/app/services/snackbar.service.ts | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/app/helperFunctions/replaceAll.ts diff --git a/src/app/graphql.module.ts b/src/app/graphql.module.ts index 4e64641..eca37c2 100644 --- a/src/app/graphql.module.ts +++ b/src/app/graphql.module.ts @@ -46,7 +46,8 @@ export function createApollo(httpLink: HttpLink, snackBar: SnackBarService): Apo if (networkError) { //console.log(`[Network error]: ${networkError}`); // THE FOLLOWING CODE IS UNTESTED - snackBar.openSnackBar("Ein NetzwerkFehler ist aufgetreten", "Ok", true, [{"message": networkError}] ); + //snackBar.openSnackBar("Ein NetzwerkFehler ist aufgetreten", "Ok", true, [{"message": networkError}] ); + snackBar.openSnackBar(JSON.stringify(networkError), "", true); } }); diff --git a/src/app/helperFunctions/replaceAll.ts b/src/app/helperFunctions/replaceAll.ts new file mode 100644 index 0000000..9fbe556 --- /dev/null +++ b/src/app/helperFunctions/replaceAll.ts @@ -0,0 +1,3 @@ +export function replaceAll(str, find, replace) { + return str.replace(new RegExp(find, 'g'), replace); +} \ No newline at end of file diff --git a/src/app/services/snackbar.service.ts b/src/app/services/snackbar.service.ts index a4bdbc4..64be747 100644 --- a/src/app/services/snackbar.service.ts +++ b/src/app/services/snackbar.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import {MatSnackBar} from '@angular/material/snack-bar'; import { ErrorSnackbarComponent } from '../helper/snackbar-ref.component'; +import { replaceAll } from 'src/app/helperFunctions/replaceAll'; @Injectable({ providedIn: 'root', @@ -11,6 +12,7 @@ export class SnackBarService { openSnackBar(message: string, action: string = "", error: boolean = false, errorMessages: Object[] = undefined) { + message = replaceAll(message, '"', ""); if (error){ if (errorMessages === undefined){ this.snackBar.open(message, action, {