1

I'm totally clueless about why error is not firing

this is the code where I call the server

this.userService.createUser(values).subscribe((response)=> {
                this.alertService.showConfirm("Usuario creado");
                this.dialogRef.close(response);
            }),error => this.alertService.showError({message: error.error.message}) 

this error is the one not firing

create user has the following code

 createUser(usuario): Observable<boolean>{
    const accessToken  = this.webStorageService.getAccessToken();
    return this.http.post<boolean>(`${this.usersUrl}?access_token=${accessToken}`, usuario,{ headers: this.headers });

where this.http is HttpClient from AngularCommon and headers is

this.headers = new HttpHeaders().set('Content-Type', 'application/json');

I have a response interceptor that catch every error response, the important code of the interceptor is the following

return throwError(err);

because I have the inteceptor only to do something if the http error is 401, but I'm sending a 400 error I have a console log of err on the interceptor and it catch the error fine, any clue why doesn't it reach the subscribe?

I've tried to remove the whole interceptor and it does not work too, so I assume is not a interceptor problem

JoseCarlosPB
  • 933
  • 2
  • 14
  • 29
  • In the line `}),error => this.alertService.showError({message: error.error.message}) `, the first `)` is not needed, don't you think? Try changing this line to `},error => this.alertService.showError({message: error.error.message}));` – AliF50 Mar 19 '20 at 17:53
  • The code says syntax error because the ) is closing the subscribe .subscribe((response)=> { .... }) after the inline function I close the subscribe – JoseCarlosPB Mar 19 '20 at 17:56
  • Close the `subscribe` after the error callback. Remove the `)` that I told you and add it towards the end `error.error.message}));` – AliF50 Mar 19 '20 at 18:15
  • thanks you!!! it worked, post as an answer and I'd gladly accept it – JoseCarlosPB Mar 19 '20 at 18:19

1 Answers1

1

In the line }),error => this.alertService.showError({message: error.error.message}) , the first ) is not needed, don't you think? Try changing this line to },error => this.alertService.showError({message: error.error.message}));. Notice the extra ) at the end of this line.

Thanks for accepting this as the answer, I appreciate it.

AliF50
  • 16,947
  • 1
  • 21
  • 37