0

I am working on Angular application. My backend returns 403 error.

 catch (AccessViolationException ex)
        {
            return StatusCode(403, ex.Message);
        }

On my frontend, my component.ts has subscribed to the method. But its not running error block. It should show error in snackbar but it is not going in error block. I can see Http error in console.

this.dataSource.deleteUser(_data.id).subscribe(
    (result) => {
      if (result.Status) {
        this.loadItems(false);
        this.snackbarService.show(_deleteMessage, 'success');
        this.selection.clear();
      } else {
        this.snackbarService.show(_message, 'danger');
      }
    },
    (error) => {
      this.snackbarService.show(error.error.Message, 'danger');
    }
  );

where DataSource class contains

deleteUser(_id: number): Observable<any> {
    return this.service.deleteUser(_id);
  }

And service class contains

  deleteUser(id: number): Observable<any> {
return this.httpService.delete('/Admin/DeleteUserRequest/' + id);

}

user14463446
  • 99
  • 10
  • because it is not an error. It will go through your success block with a status code of 403. https://stackoverflow.com/questions/51049806/how-to-read-the-status-from-response-in-angular-http –  Jun 29 '22 at 23:46
  • @E.Maggini I can see httperrorresponse in Console but i want error to go to subscribe's error block – user14463446 Jun 30 '22 at 00:36
  • That is simply a response code from the server, the call itself was successful. If you wish to over ride this behavior you could probably use an http interceptor. Probably something like this https://javascript.plainenglish.io/angular-handle-http-errors-using-interceptors-5cc483103740 –  Jun 30 '22 at 01:48

0 Answers0