Closed andymckay closed 8 years ago
So I found out what causes this, but didn't get a satisfactory answer.
handle500
is set to this: https://github.com/mozilla/olympia/blob/master/apps/amo/views.py#L112-L117
Which looks to see if it starts with /api/
and then bounces you over to /apps/api/
which returns XML because the main API on olympia is version check and block list. Change this at your peril.
So the next obvious thing to do is override the exception handler in DRF: http://www.django-rest-framework.org/api-guide/exceptions/, but if you do that and its a 500, nothing gets sent to sentry. So then if you try to add in sentry logging in the exception handler, you'll note that you don't actually get the request.
So then I thought I'd just change the handler500
in /apps/api/
and we can do that by simply checking request.path_info.startswith('/api/v3/')
, but then ideally you want to create a Response that adapts to the Accept headers sent by the client. Which a standard rest framework Response won't do.
At that point I headed for a beer. There's probably something simple here I'm missing.
Duplicate of mozilla/addons#3137, but it looks like @diox is working on that one 👍
Ah yeah, had not seen your issue. I'll look into playing with the DRF exception handler, I did that in Marketplace and had the request working : https://github.com/mozilla/zamboni/blob/master/mkt/api/exceptions.py#L38
If a request comes into something on the API its asking for json, don't return HTML on an error. Example:
I'm requesting JSON and get back XML.