AnsweredAssumed Answered

How do I handle a service URL that returns an HTML page with a HTTP 200 code

Question asked by bryanboutz on Aug 18, 2016
Latest reply on Sep 22, 2016 by bryanboutz

Occasionally one of the services used by my application but that I don't control fails and starts returning HTML content with a 200 HTTP code rather than any error code or even a valid JSON response with an error.  The specific scenario hanging me up is that the web adaptor server putting up an error page instead of passing through to the map service, but I've also seen it happen when an overzealous security rule blocks a request.  For my purposes, I am testing this by pointing a map to a static html page.


When this happens, I have just called map.addLayers with the bad layer included. The console then shows "init.js:182 SyntaxError: Unexpected token <"  and it appears the problem is Dojo trying to parse JSON. (Stack trace is below).  What really hurts is that this then stops the map from firing the onLayersAddResult event so I am not able to do additional application setup tasks that are needed after the map loads.  To be fair, I haven't tried using on("Layers-Add-Result") or adding a single layer at a time as that would require significant rework of my app.


I have a few ugly ideas for work-arounds, but I'm hoping someone has a more elegant suggestion. I should say, this is using the 3.14 API, but I got the same results from the current 3.17 version.


Stack trace from console:
init.js:182 SyntaxError: Unexpected token <

at Object.b.fromJson (
at Object.json (
at s (
at c (
at d (
at resolve.callback (
at k (
at m (
at f.resolve (