diff options
Diffstat (limited to 'so-admin-cockpit-monitoring-workflow/so-admin-cockpit-monitoring-workflow-ui/src/main/frontend/src/app/http-error-handler.service.ts')
-rw-r--r-- | so-admin-cockpit-monitoring-workflow/so-admin-cockpit-monitoring-workflow-ui/src/main/frontend/src/app/http-error-handler.service.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/so-admin-cockpit-monitoring-workflow/so-admin-cockpit-monitoring-workflow-ui/src/main/frontend/src/app/http-error-handler.service.ts b/so-admin-cockpit-monitoring-workflow/so-admin-cockpit-monitoring-workflow-ui/src/main/frontend/src/app/http-error-handler.service.ts new file mode 100644 index 0000000..33f4812 --- /dev/null +++ b/so-admin-cockpit-monitoring-workflow/so-admin-cockpit-monitoring-workflow-ui/src/main/frontend/src/app/http-error-handler.service.ts @@ -0,0 +1,53 @@ +/** +============LICENSE_START======================================================= + Copyright (C) 2018 Ericsson. All rights reserved. +================================================================================ +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and + limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +============LICENSE_END========================================================= + +@authors: ronan.kenny@est.tech, waqas.ikram@est.tech +*/ + +import { Injectable } from '@angular/core'; +import { ToastrNotificationService } from './toastr-notification-service.service'; +import { HttpErrorResponse } from '@angular/common/http'; +import { Observable, of, throwError } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) +/** Handles HttpClient errors */ +export class HttpErrorHandlerService { + + constructor(private popup: ToastrNotificationService) { } + + handleError(operation = 'operation', url = 'url') { + return (error: HttpErrorResponse) => { + if (error.error instanceof ErrorEvent) { + console.error('An error occurred:', error.error.message); + this.popup.error("An error occurred for operation: " + operation + " using url: " + url + " Detail: " + error.error.message); + return throwError("An error occurred for operation: " + operation); + } + if (error.status == 500 || error.status == 0) { + this.popup.error("Internal Service Error occured for operation: " + operation + " please check backend service log. status code: " + error.status); + } + console.error( + 'Backend returned status code: ', error.status + ' from URL ' + url); + return throwError(error.error || "Internal Service Error occured for operation: " + + operation + ". Please check backend service log. Status code: " + error.status); + }; + + } +} |