- Code: Select all
<!DOCTYPE html>
<h1 style="color:red">Bad Request</h1>
<p>Sorry, I don't know what you're asking for.
<p style="font-size:small">Error: 400 Bad Request
<p><a href="/pages/api.html">The NationStates API Documentation</a>
I've found this format a bit difficult to work with. Some XML parsers can't handle this data (mainly due to the lack of closing </p> tags or a root node). That leaves a few options, like bringing in an HTML parser, parsing out the error message with regex, or guessing the error based on the status code, but those all feel a bit clunky or ambiguous to me. Given that the API returns data in XML, I think it would also make sense to return errors in XML. Just spitballing here, but perhaps something like this?
- Code: Select all
<ERROR>
<MESSAGE>Bad Request</MESSAGE>
<DETAILS>Sorry, I don't know what you're asking for.</DETAILS>
</ERROR>
I realize this could make error responses less readable to the end user, but I think it's not that difficult to read this kind of response and I would also imagine that the vast majority of traffic to the API is from bots rather than humans.
I also realize this would not be backward-compatible, but according to the documentation, the API already may be updated without notice, and scripts can always specify an API version if necessary.