GithubHelp home page GithubHelp logo

Don't return HTML in the API about addons HOT 3 CLOSED

mozilla avatar mozilla commented on September 26, 2024
Don't return HTML in the API

from addons.

Comments (3)

andymckay avatar andymckay commented on September 26, 2024

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.

from addons.

andymckay avatar andymckay commented on September 26, 2024

Duplicate of #3137, but it looks like @diox is working on that one 👍

from addons.

diox avatar diox commented on September 26, 2024

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

from addons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.