This is a call to the GBIF API. There is an intential error in the call that gives an error message from the server
com.spatial4j.core.exception.InvalidShapeException: Invalid latitude: latitudes are range -90 to 90: provided lat: [-125.0]
In R with httr
:
library(httr)
call <- "http://api.gbif.org/v0.9/occurrence/search?geometry=POLYGON((38.4 -125, 40.9 -125, 40.9 -121.8, 38.4 -121.8, 38.4 -125))"
a <- GET(call)
None of the metadata from the call, as far as I know, gives the error message.
You can parse the message out
library(XML)
doc = htmlParse(content(a, as="text"))
xpathSApply(doc, "//h1", xmlValue)
[1] "HTTP Status 500 - com.spatial4j.core.exception.InvalidShapeException: Invalid latitude: latitudes are range -90 to 90: provided lat: [-125.0]"
But I wonder if there is a general solution available in httr
that works beyond just this example.
Perhaps the server error above should be in the header?
All you get from http is a status code - in this case 500, which means "Internal Server Error". The server can return anything it likes in the body, there's no standard for passing more error info except as text after the status code. I'm not sure if compliant servers can vary what they put after the status code...
You can get the status code from
a$headers$status
and the message ina$headers$statusmessage
but thats it.