-
Notifications
You must be signed in to change notification settings - Fork 8
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
better handling of geojson parsing exceptions #164
Conversation
currently, there already is a 400 error code returned if the bpolys parameter is invalid for a count request: Does this fix only affect some endpoints and not others? Or just special cases of (geo)json parsing errors?
Are these two independent bugfixes combined in one PR, or is this somehow related to the fix for the geojson parsing? It would be fine either way, just asking to understand. |
src/test/java/org/heigit/ohsome/ohsomeapi/controller/GetControllerTest.java
Outdated
Show resolved
Hide resolved
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.
This doesn't fix all null pointer dereferencing. Try this:
{
"type": "FeatureCollection"
}
Even after applying this PR I still get a NullPointerException at GeometryBuilder.createGeometryFromGeoJson(GeometryBuilder.java:221)
:
{
"timestamp" : "2021-03-25T11:23:28.923+0000",
"status" : 500,
"error" : "Internal Server Error",
"message" : "No message available",
"path" : "/elements/count"
}
also, for an empty feature collection ({"type": "FeatureCollection", "features": []}
), the error code could be improved. Currently, it falsely states that the boundary does not lie withing the covered area:
{
"timestamp": "2021-03-25T11:20:29.676167",
"status": 404,
"message": "The provided boundary parameter does not lie completely within the underlying data-extract polygon.",
"requestUrl": "https://api.ohsome.org/v1/elements/count?bpolys=%7B%20%20%20%22type%22%3A%20%22FeatureCollection%22%2C%20%20%20%22features%22%3A%20%5B%5D%20%7D&filter=type%3Away%20and%20natural%3D*&format=json&time=2014-01-01%2F2017-01-01%2FP1Y"
}
Is silently skipping of tests really the best approach? I mean tests can be skipped on purpose by adding |
btw, the actual line of code is ohsome-api/src/main/lombok/org/heigit/ohsome/ohsomeapi/inputprocessing/GeometryBuilder.java Lines 236 to 237 in 68d9484
Sadly because of lombok (#57), the reported code lines in error messages don't align with our sources anymore. 😢 |
It's a fix for the given example of @SlowMo24 in #55, which was before not caught and just returned an error message that was not helpful. |
I understood that. However it would be nice to summarize what exactly was fixed here in this PR. For example, #55 only gives one single failing query, but the actual problem is a bit bigger it seems to me. |
I disagree here. The statement
It does not say anywhere that this branch fixes every possible GeoJSON parsing exception. Of course we can make this functionality more robust within this branch.
This approach with executing the tests when the required command line parameters are given has already been discussed in the past as far as I know. You get the message in the commandline stating e.g. |
Well, this depends on how you handle empty collections in general. One commonly found approach is the so called vacuous truth, which would assign the answer I agree that it's definitely not something critical, and I can also live with the status quo, but IMHO it would be nicer to show the same or a similar error message to |
But I (the reviewer of this PR) say so. 😝 |
Hm ok.. viewing it through this vacuous truth statement, the currently returned error message would actually not be fitting. Still the question is how specific we want to be with our exception messages and on how much
:D Yeah that's why I said we can potentially fix more stuff within this branch. I'll put it back to WIP then to adress the discussed stuff and check for potential further parsing issues that might arise. Initially I just thought of fixing the linked issue, but yeah it would make sense to invest more time into that branch. |
You are right. I also think that people should be clever enough to figure this out. Let's keep it as it is. |
I've moved more lines into the try-catch block and extended the error response message. Please have a look again @tyrasd. |
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.
Overall it looks good to me now, just two small-ish suggestions. See below.
src/main/lombok/org/heigit/ohsome/ohsomeapi/inputprocessing/GeometryBuilder.java
Outdated
Show resolved
Hide resolved
941b68f
to
21d3aff
Compare
to give a proper 400 - BadRequestException
that has a feature collection but no geometry field
so the tests are properly skipped when no port1 parameter is set
move further lines into try-catch block increase exception message usability add test for invalid geojson input
minor wording adaption Co-authored-by: Martin Raifer <martin.raifer@heigit.org>
add content of unlikely triggered if statement to exception message above and remove if statement
Description
catching geojson parsing exception to give a proper 400 - BadRequestException
fix of not properly working GetControllerTest class in case no port1 parameter was given
Corresponding issue
Closes #55
Checklist
I have commented my codeI have written javadoc (required for public methods)I have made corresponding changes to the documentationI have adjusted the examples in the check-ohsome-api script or created an issue in the corresponding repository. More Information here.