openverse-api
openverse-api copied to clipboard
Remove `get_api_exception` and replace with built in DRF exceptions
Description
The bespoke get_api_exception function recreates built in DRF functionality and makes searching for particular exceptions more difficult. Instead of searching for raise NotFound or raise <built-in-DRF-exception>, the typical way to find code that explicitly raises exceptions, you'd have to know about the get_api_exception function and search for usages with the specific HTTP status code (which has to be hand written by the user each time, meaning they have to remember what the status code is).
It also obscures stack traces because all errors created by get_api_exception have the same name (only solvable by further meta programming using the type constructor instead of a closed class): https://sentry.io/share/issue/abf49297eb2749e889eff15e4d37e151/
In short: we can eliminate code by removing this, be more in line with default DRF functionality and the community.
- Replace all usages of
get_api_exceptionfunction with the appropriate built-in DRF exception fromrest_framework.exceptions. For any that are following thetry: queryset.get(); except Model.DoesNotExist: ...pattern, replace it withget_object_or_404. - Remove the
get_api_exceptionfunction
Hello @sarayourfriend, I am new to open source and I would like to work on this.
Hi @AbhiYHub! That's great, thank you for your willingness to contribute :slightly_smiling_face: I've assigned the issue to you. If you have any questions here or run into issues during implementation, please feel free to ping me or @WordPress/openverse-maintainers for help.
Hello @sarayourfriend !! I am looking to start my journey in Open Source projects. Could you please assign this issue to me?
Hello @sarayourfriend and @dhruvkb, Apologies for the delay. I have solved the issue and also ran the test cases. All the test cases have passed successfully. I would request if you can reassign me the task so that I could submit the solution.
@AbhiYHub please push your solution as a PR. Thanks!