New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle errors in response parsing in xhr loader #15808
fix: handle errors in response parsing in xhr loader #15808
Conversation
📦 Preview the website for this branch here: https://deploy-preview-15808--ol-site.netlify.app/. |
277e179
to
53558f2
Compare
); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Striclty speaking this if-else
is not needed anymore, since a falsy source would throw an error which is then caught and calls failure();
, but it seemed cleaner to keep it.
53558f2
to
90a848e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebakerckhof A slightly related note: for GeoServer, when requesting WFS in JSON format, you should configure it to also return exceptions in JSON. See https://docs.geoserver.org/latest/en/user/services/wfs/reference.html#exceptions. That does not change the response status code though.
It would be good if you could change the test to use the JSON version of the exception. Also, there is no need to call JSON.parse()
in the featureloader, because the format will handle that. Also for XML formats, there is no need to parse the XML. Simplifying that would make the code easier to read, I think.
Ah, I didn't know about that option, thanks. But indeed, it doesn't change the need for the try-catch that this PR adds. I added a test for the json exception, but kept the xml test as well, since it's not wrong for the server to send an xml report from what I got from the spec. The redundant parsing is removed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @sebakerckhof
Although I'm not sure if/what the OWS spec says about this, but at least the popular geoserver will return status 200 even when the result is an OWS exception report.
E.g. If I make a WFS call that fails in geoserver. I'll get a status 200 with an ows exception report XML.
e.g.
The problem is that the xhr loader does not account for this and will throw an uncaught error when trying to parse it as json.
Therefore the failure/success callbacks are never called and the source stays in loading state (and in turn rendercomplete is not called)
This PR tries to solve this by putting wrapping the entire data parsing in a try-catch