angular2-jsonapi icon indicating copy to clipboard operation
angular2-jsonapi copied to clipboard

Overriding handleError

Open mangicapra opened this issue 5 years ago • 1 comments

"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 :)

mangicapra avatar Apr 30 '20 05:04 mangicapra

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

  • getDirtyAttributes
  • toQueryString

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

hpawe01 avatar Jan 21 '21 10:01 hpawe01