angular - How to return custom catch error in Observable Http? -


i have observable function, request:

public send(): observable<isms[]> {      if (this.usedattempts < this.maxattempts) {       return; // here return custom error     } } 

i take observable as:

this.sms.send().subscribe(       response => {         console.log(response);       },       error => {         console.log(error);       }     );   } 

i need check if user can send sms if yes, send, otherwise return error.

just use throw() operator:

if (this.usedattempts < this.maxattempts) {     return observable.throw('error description'); } 

don't forget import it:

import 'rxjs/add/observable/throw'; 

here the docs say:

creates observable emits no items observer , emits error notification.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -