API 400 Error responses should be in JSON, not HTML

Ben Davis avatarBen Davis created an issue

400 error responses are currently returned as difficult-to-parse HTML:

<ul class="errorlist">
  <li>name
    <ul class="errorlist"><li>You already have a repository with this name.</li></ul>
  </li>
</ul>

It stands to reason that json should be the default response type, since the response type for successful API calls is also json.

At the very least, the API should respect the Accept: header in the request. For example, if I send a request with the header "Accept: application/json", the API should know I want json and return that.

{
    "errorlist": [
        {"name": ["You already have a repository with that name"]}
    ]
}

Comments (6)

  1. Jon Mooring

    Hi Ben Davis, thanks for the report. All of our v2 APIs should send JSON error responses. In order to prevent breaking compatibility, we chose not to make the same changes to our v1 APIs. Is it the case that you're using a v1 API?

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.