simple angular http sandbox

Just simple http sandobx


  1. Abort on different event
    1. for example – another observable, another click etc
  2. Catch error on bad response (not jsonable)
    1. Just example how to catch error in observable flow
  3. Timeout
    1. some backend works not really ok, sometimes api requested are freeze – and next call – its OK, you can handle this
  4. Retry after error
    1. when json is wrond, and timeout will call – but you really need response – try again many times call the same request
  5. Filter value && default value
    1. you can also use map() or filter and default value
this.abort = Observable.fromEvent(document, 'click').do(() => this.log('DOCUMENT CLICK - ABORT'));

this.log('WAIT FOR GET');
this.result$ = this.http
    .map(res => res.json())
    .catch(e => Observable.throw(ApiErrors.JSON_FORMAT + e))
    .timeoutWith(1000, Observable.throw(ApiErrors.TIMEOUT))
    .catch(e => Observable.throw(ApiErrors.RETRY_FAILED + e))
    .filter(v => v > 50)
    .catch(e => {
        return Observable.throw(e);