GIScience / ohsome-api

API for analysing OpenStreetMap history data
https://api.ohsome.org
GNU Affero General Public License v3.0
47 stars 8 forks source link

(early) timeouts in data extraction request return HTTP/500 instead of 4xx error code #10

Closed tyrasd closed 4 years ago

tyrasd commented 4 years ago

When using a relatively short timeout with a data extraction request and the timeout hits before the first chunk of data was sent, the result is a HTTP/500 error code (internal server error) instead of a 4xx error code (invalid request, e.g. 413 like it is thrown by the data aggregation endpoints).

Also the error description is not very useful in this case:

$  curl -v "https://api.ohsome.org/v1/elements/geometry?bboxes=-180,-90,180,90&timeout=1"
…
< HTTP/1.1 500 
…
{
  "timestamp" : "2020-06-16T08:49:00.789+0000",
  "status" : 500,
  "error" : "Internal Server Error",
  "message" : "Remote job threw user exception (override or implement ComputeTask.result(..) method if you would like to have automatic 
failover for this exception): null",
  "path" : "/elements/geometry"
}

As far as I can see in the logs, the correct OSHDBTimeoutException is thrown, but not properly catched and handled by the ohsome API.

bonaparten commented 4 years ago

I tested it locally by starting the ohsome API in eclipse for the request http://localhost:8080/elements/geometry?bboxes=-180,-90,180,90&timeout=1 (using a local H2 oshdb database file). There, the error is not reproducible. In my case I get an HTTP/200 status and in the returned json content an error message 413, which is how it should be.

{
  "attribution": {
    "url": "https://ohsome.org/copyrights",
    "text": "© OpenStreetMap contributors"
  },
  "apiVersion": "1.0.0-SNAPSHOT",
  "type": "FeatureCollection",
  "features": [
    {
      "timestamp": "2020-07-01T10:07:45.635474",
      "status": 413,
      "message": "The given query is too large in respect to the given timeout. Please use a smaller region and/or coarser time period.",
      "requestUrl": "http://localhost:8080/elements/geometry?bboxes=-180,-90,180,90&timeout=1"
    }

But this seems to be only the behaviour when using a local H2 oshdb file, since the problem is easily reproducible in swagger: I tested in swagger smaller bboxes and I got back arbitrarily 500 and 413 errors with bboxes of sizes ranging between about 1 and 4 (e.g. -3,-1.5,3,1.5).

https://api.ohsome.org/v1/elements/geometry?bboxes=-3,-1.5,3,1.5&timeout=1

tyrasd commented 4 years ago

Note: This issue was closed automatically because the causing bug was fixed in the oshdb 0.6-SNAPSHOT (master branch). Once it gets into an OSHDB release and this is pulled in from the ohsome-api, it will finally also fix this bug here.