ReactiveX / ReactiveX/rxjs

errors in .ajax are not propagated to .catch

Open
#2,583 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

hello,

it seems that errors may not be being properly handled in the ajax operator.

RxJS version:

5.3.0

Code to reproduce:

// index.js (run in node, after installing rxjs, nock, & xmlhttprequest)
var nock = require('nock')
var Observable = require('rxjs').Observable
global.window = global
global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest

nock('http://example.com').get('/test/1').reply(200, '!!INVALID-JSON!!') // :eyes:

var obs = Observable
.from([1])
.switchMap(action => {
  return Observable
  .from([2])
  .ajax({ url: 'http://example.com/test/1', method: 'GET' }) // does not work per expectation
  // .map(({ response }) => { throw new Error('bananas') }) // works per expectation
  .catch(err => {
    console.error(err.message) // never reached when JSON wasn't parseable from ajax request
    process.exit()
  })
})

obs.subscribe(arg => console.log('bananas'))

Expected behavior:

.catch entered

Actual behavior:

.catch not entered

Additional information:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the index.js reproduction against RxJS 5.3.0 and trace the ajax operator's handling of the invalid JSON response. The work is done when the malformed response reaches .catch as an error, matching the expected behavior described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.