beautified error handling

apollointerceptor
FlayInAHook 4 years ago
parent 645c234216
commit 7ad1bb01e9

@ -46,7 +46,8 @@ export function createApollo(httpLink: HttpLink, snackBar: SnackBarService): Apo
if (networkError) { if (networkError) {
//console.log(`[Network error]: ${networkError}`); //console.log(`[Network error]: ${networkError}`);
// THE FOLLOWING CODE IS UNTESTED // 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);
} }
}); });

@ -0,0 +1,3 @@
export function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {MatSnackBar} from '@angular/material/snack-bar'; import {MatSnackBar} from '@angular/material/snack-bar';
import { ErrorSnackbarComponent } from '../helper/snackbar-ref.component'; import { ErrorSnackbarComponent } from '../helper/snackbar-ref.component';
import { replaceAll } from 'src/app/helperFunctions/replaceAll';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -11,6 +12,7 @@ export class SnackBarService {
openSnackBar(message: string, action: string = "", error: boolean = false, errorMessages: Object[] = undefined) { openSnackBar(message: string, action: string = "", error: boolean = false, errorMessages: Object[] = undefined) {
message = replaceAll(message, '"', "");
if (error){ if (error){
if (errorMessages === undefined){ if (errorMessages === undefined){
this.snackBar.open(message, action, { this.snackBar.open(message, action, {

Loading…
Cancel
Save