Page MenuHomePhabricator

Improve error responses from API endpoints
Closed, ResolvedPublic

Description

While testing the pagination features of T264970, I noticed that the frontend error reported when attempting to submit a duplicate URL is very generic: "Uh oh! Something went wrong. Error: Bad Request".

Looking at the raw response from the backend API shows a bit more information, but also that the information is in a very generic structure:

{
  "url": [
    "crawled url with this url already exists."
  ]
}

String based error reporting is the sort of thing that makes API client authors angry. It makes it very difficult to take automated actions based on the response as interpreting the error requires natural language parsing or hard coding string to state mappings in the client.

We should try out drf-friendly-errors as a way to add structure and documentable error codes to the API's error responses.

Event Timeline

bd808 triaged this task as Medium priority.Nov 6 2020, 9:40 PM

It turns out that the drf-friendly-error project has not been updated for ~4 years which sadly makes it not compatible with the version of DRF that we are using. There are a few forks of the library which have been updated for internal projects at various orgs, but none of these are currently published on pypi.

I found a fork of drf-friendly-error which has had more recent activity and is also published on pypi. I have submitted a PR to that fork (https://github.com/citixensas/drf-friendly-errors/pull/2) to add support for the newer version of django-rest-framework that we are using. Let's cross our fingers and hope that we don't have to maintain yet another fork ourselves. :)

bd808 moved this task from Backlog to In Progress on the Toolhub board.

Change 641008 had a related patch set uploaded (by BryanDavis; owner: Bryan Davis):
[wikimedia/toolhub@main] api: improve error responses from API endpoints

https://gerrit.wikimedia.org/r/641008

Change 641008 merged by jenkins-bot:
[wikimedia/toolhub@main] api: improve error responses from API endpoints

https://gerrit.wikimedia.org/r/641008