etalab / transpo-rt

Simple API for public transport realtime data
https://tr.transport.data.gouv.fr/
GNU Affero General Public License v3.0
21 stars 9 forks source link

Errors are sent in text/plain rather than json content-type #112

Open thbar opened 3 years ago

thbar commented 3 years ago

During my manual tests of #109, I noticed that when the base schedule is not available, we get a text/plain error currently.

Here is an example, using a local test config and querying http://localhost:8080/test:

HTTP/1.1 502 Bad Gateway
content-length: 170
connection: close
content-type: text/plain; charset=utf-8
date: Mon, 18 Jan 2021 10:01:12 GMT

theoretical dataset temporarily unavailable : impossible to read GTFS http://localhost:8000/SEM-GTFS.zip because Invalid Zip archive: Could not find central directory end

Since the whole API is JSON, I believe standardising on JSON content-type of errors would be better for the end-user life.

Useful resources

thbar commented 3 years ago

The encoding is also not set as a header, leading to this output on some browsers:

CleanShot 2021-01-18 at 11 58 38@2x

It would be a good idea to fix this at the same time, with a Content-Type: application/json; charset=utf-8 (but maybe just switching to JSON) will correct that as well, actually.