reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Service.get calls success handler even though error occured #264

Open baranchikovaleks opened 4 years ago

baranchikovaleks commented 4 years ago

Hi there!

Here is a simple snippet

this.someService.get(resource_id).pipe(
  catchError(() => of(1))
).subscribe((response) => {
    console.log(response);
  },
);

In case of server error (e.g. 404 Not Found) there will be at least 2 lines printed

$some not properly built resource where is_loading === true
1

A bit re-worked example

this.someService.get(resource_id).pipe(
  catchError(() => throwError(1))
).subscribe((response) => {
    console.log(response);
  },
  error => {
    console.log(error);
  }
);

The output is the same 2 lines as above.

So we end up with handling not properly built object wihtout knowing that there was an error! That looks like a bug in the library.

My suggestion is to remove emitting a resource in before error (in case there is any) here https://github.com/reyesoft/ngx-jsonapi/blob/v2.1/src/service.ts#L164-L165

Or at least add something that indicates that there was an error occured.