Chatra
Chatra

Reputation: 3139

Handle boolean response and error in right way - Angular 6

Below is my code. I am not sure whether my implemenation is right.

Service returns boolean value. What if the subscribe returns error?

this._service
  .UpdatesStatus(this.transaction)
  .subscribe((response: boolean) => {
    if (response) {
      this._notificationService.success('Accepted.', 'Accepted');

    } else {
      this._notificationService.error(
        'Failed.',  'Failed'
      );
    }
  }, (error) => {
    this._logrovider.error(error.message);
  }, () => {
    this._loaderService.isLoading(false);
  });

Upvotes: 0

Views: 260

Answers (1)

Mr-K10
Mr-K10

Reputation: 345

If the request processes successfully, It will either return true or false. And it depends on your server if it returns false for error.

But if there are some errors that are not handled by the server or may cause server error, they will be handled by error block of subscribe

(error) => {
  this._logrovider.error(error.message);
}

Upvotes: 1

Related Questions