Skip to content

Error handling

Michael Dostál edited this page Nov 14, 2018 · 1 revision

Error handling is done in the subscribe method of the returned Observables. If your server returns valid JSON API Error Objects you can access them in your onError method:

import {ErrorResponse} from "angular2-jsonapi";

...

this.datastore.findAll(Post).subscribe(
    (posts: Post[]) => console.log(posts),
    (errorResponse) => {
        if (errorResponse instanceof ErrorResponse) {
              // do something with errorResponse
              console.log(errorResponse.errors);
        }
    }
);

It's also possible to handle errors for all requests by overriding handleError(error: any): Observable in the datastore.

Clone this wiki locally