ghidoz / angular2-jsonapi

A lightweight Angular 2 adapter for JSON API
199 stars 123 forks source link

Overriding handleError #267

Open mangicapra opened 4 years ago

mangicapra commented 4 years ago

"angular2-jsonapi": "^8.2.1"

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

So i'm interested how can i achieve this behaviour? This is auth datastore and should it be possible to override it in here.

const config: DatastoreConfig = { baseUrl: ${environment.baseUrl}/auth, models: { login: Login, refresh: Refresh, }, }; @Injectable({ providedIn: 'root', }) @JsonApiDatastoreConfig(config) export class DatastoreService extends JsonApiDatastore { constructor(public http: HttpClient) { super(http); } }

Thanks :)

hpawe01 commented 3 years ago

This seems to be an incorrect statement in the README, because the only methods that can be overwritten are

The override mechanism is described here and it works by adding the overwriting methods in the overrides property of the datastore config object.

But you could implement this method in a PR similar to the above methods: https://github.com/ghidoz/angular2-jsonapi/blob/master/projects/angular2-jsonapi/src/services/json-api-datastore.service.ts#L33