jfinkels/flask-restless — pull request #366 by devkeh (2014-10-17 17:27:30+00:00)
Title: Fixed issue #362 - Unhandled HTTP Exceptions returning HTML instead of JSON

I have implemented a fix that forces all unhandled exceptions to be converted into a JSON response. Previously the framework was returning unwanted HTML responses which could potentially break RESTful clients expecting a JSON formatted response.

```
HTTP/1.0 404 NOT FOUND
Content-Type: text/html
Content-Length: 233
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Fri, 17 Oct 2014 17:20:57 GMT

404 Not Found

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

```

```
HTTP/1.0 405 METHOD NOT ALLOWED
Content-Type: text/html
Allow: POST, OPTIONS
Content-Length: 178
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Fri, 17 Oct 2014 17:23:01 GMT

405 Method Not Allowed

Method Not Allowed

The method is not allowed for the requested URL.

```

After this fix now all exceptions are returned in JSON format as shown below.

```
HTTP/1.0 404 NOT FOUND
Content-Type: application/json
Content-Length: 33
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Fri, 17 Oct 2014 17:25:43 GMT

{
"message": "404: Not Found"
}
```

```
HTTP/1.0 405 METHOD NOT ALLOWED
Content-Type: application/json
Content-Length: 42
Allow: OPTIONS, POST
Server: Werkzeug/0.9.6 Python/3.4.2
Date: Fri, 17 Oct 2014 17:25:01 GMT

{
"message": "405: Method Not Allowed"
}
```