authn-js icon indicating copy to clipboard operation
authn-js copied to clipboard

Stop jhr XHR function from swallowing JSON.parse error

Open silasdavis opened this issue 6 years ago • 1 comments

There are a number of circumstances where the server may return a non-empty non-JSON response:

  • Connection refused
  • Bad origin
  • Failure to reverse proxy
  • Other middleware

In these cases jhr dies silently and so the front end cannot easily display an error message. This change wraps the JSON parsing in a function with a try catch and returns an appropriate error.

I have an issue with the tests - the pass successfully in the browser (by loading runner.html) but they fail with yarn test which complains with Failed assertion: expected: [object Object], but was: [object Object]. This is different to failure in the browser UI that gives you a nice string diff between the objects. it seems like gulp-qunit is ending up with a different broken implementation of deepEqual. I tried upgrading gulp-qunit and qunit but it didn't help. Perhaps you have an idea how to fix, otherwise we can work around it some other way. It's odd because I don't see the difference between the other usages that work fine.

silasdavis avatar May 30 '19 10:05 silasdavis

I think it's a legacy issue in PhantomJS. The console logger isn't as capable.

Speaking of PhantomJS issues -- the expected error is different, too:

HTTP response 'Origin is not a trusted host.' is not JSON as expected: SyntaxError: JSON Parse error: Unexpected identifier "Origin"

cainlevy avatar Jun 01 '19 03:06 cainlevy