/**
 * Copyright 2017 - 2018  The Hyve B.V.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */ import { HttpErrorResponse } from '@angular/common/http' ; import { MessageHelper } from './message-helper' ; export class ErrorHelper { param error { HttpErrorResponse | any } static handleError ( error ) { if ( ! ( error instanceof HttpErrorResponse ) ) { console . error ( `Error: ${ error }` , error ) ; return ; } if ( error . error instanceof ErrorEvent ) { console . error ( 'A client-side or network error occurred:' , error . error . message ) ; MessageHelper . alert ( 'error' , 'A client-side or network error occurred' ) ; return ; } const status = error . status ; const url = error . url ; const message = error . message ; const summary = `Status: ${ status }\nurl: ${ url }\nMessage: ${ message }` ; console . error ( summary ) ; console . error ( error . error ) ; if ( status === 401 ) { MessageHelper . alert ( 'error' , 'Unauthorised' ) ; } else if ( status === 403 ) { MessageHelper . alert ( 'error' , 'Access denied' ) ; } else { MessageHelper . alert ( 'error' , 'A server-side error occurred' ) ; } } }