Starts in:
2 DAYS
0 HR
22 MIN
0 SEC
Starts in:
2 D
0 H
22 M
0 S

HTTP Error Reporter Service

HttpErrorReporterService is a service which is exposed by @abp/ng.core package. HTTP errors can be reported by using this service. The service emits an event when an error is reported and keeps the errors as an array. The RestService uses the HttpErrorReporterService for reporting errors.

See the example below to learn how to report an error:

import { HttpErrorReporterService } from '@abp/ng.core';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { catchError } from 'rxjs/operators';

@Injectable()
export class SomeService {
  constructor(private http: HttpClient, private httpErrorReporter: HttpErrorReporterService) {}

  getData() {
    return this.http.get('http://example.com/get-data').pipe(
      catchError(err => {
        this.httpErrorReporter.reportError(err);
        return of(null);
      }),
    );
  }
}

See the following example to learn listening the reported errors:

import { HttpErrorReporterService } from '@abp/ng.core';
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable()
export class MyErrorHandler {
  constructor(private httpErrorReporter: HttpErrorReporterService) {
    this.handleErrors();
  }

  handleErrors() {
    this.httpErrorReporter.reporter$.subscribe((err: HttpErrorResponse) => {
        // handle the errors here
    });
  }
}

API

reporter$: Observable<HttpErrorResponse>

reporter$ is a getter, returns an observable. It emits an event when a new error is reported. The event value type is HttpErrorResponse.

errors$: Observable<HttpErrorResponse[]>

errors$ is a getter, returns an observable. It emits an event when a new error is reported. The event value is all errors reported at runtime.

errors: HttpErrorResponse

errors is a getter that returns all errors reported.

reportError(error: HttpErrorResponse): void

reportError is a method. The errors can be reported via this. When an error is reported, the method triggers the reports$ and errors$ observables to emit an event.

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More