Elad Benda Elad Benda - 1 year ago 186
HTTP Question

What's the observable equivalent to `Promise.reject`

I had this code

return this.http.get(this.pushUrl)
.then(response => response.json().data as PushResult[])

I wanted to use
instead of

how can i return the error to the calling method?

What's the equivalent to

doSomeGet() {
console.info("sending get request");

.forEach(function (response) { console.info(response.json()); })

private handleError(error: any) {
console.error('An error occurred', error);
// return Promise.reject(error.message || error);

the calling method was:

getHeroes() {
// .then(pushResult => this.pushResult = pushResult)
// .catch(error => this.error = error);

Answer Source
private handleError(error: any) {
  return Observable.throw('Some error information);

See also How to catch exception correctly from http.request()?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download