The package idea is simple: let’s create DRF APIs that care about error responses as much as they care about successful ones. As developers, It’s easy for us to focus on the API implementation for successful responses and forget about the pain of dealing with an API that provides different formats for error responses or that doesn’t even document its error responses. This is why I created drf-standardized-errors: it’s an exception handler that makes it easy to return a standard error format that is properly documented out of the box.
Features:
-
Highly customizable: we’re developers and we each have our own opinion about what’s the best format. So, one important goal was to allow customization of the exception handling process without having to rewrite the everything in exception handler.
-
Out of the box support for list and nested serializer errors: even if you have that one complicated API endpoint, we’ve got you covered.
-
Plays nicely with error monitoring tools (like Sentry, …): unhandled exceptions will still be reported to error monitoring tools while also returning the standard format to API consumers.
-
Generate OpenAPI3 schema for error responses using drf-spectacular: No API is complete without proper documentation. This is work in progress (PR1 and PR2). Most of it is done, but I still need to add tests and documentation. Hopefully, that will be done over the next few week(end)s. But, if you want to get a glimpse on the expected result, here’s a screenshot of a test endpoint using swagger UI.
If you’d like to take the package for a spin, here’s a link to the quickstart guide. If you want to know more about the error response format, it’s documented here. If you don’t like that format, always remember that you can change it.
Would be happy to hear what you think and any suggestions for improvements. Thanks!