Bypassing APIExceptions completely #8175
Unanswered
deepaks829
asked this question in
Question & Answer
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to understand the implications of the following design choice for an application built using DRF.
From what I understand, the handler for a specific request is determined within the
rest_framework.views.APIView.dispatch
method and thehandler
gets called within thetry...catch..
block in thisdispatch
method. So this way any exceptions that are raised during the execution of the handler are caught within thedispatch
method are delegated to the exception handler (default or custom). As we can see here the dispatch method catches not anAPIException
but any and allException
.So could I simply raise my own
CustomException
through out my application and simply handle all these exceptions the way I want in thecustom_exception_handler
?I understand that the
ValidationError
will be an exception to this, as the serializers and in-built validators all raiseValidationError
. If I can override therest_framework.serializers.Serializer.is_valid
inMyCustomSerializer
I can catch therest_Framework.serializers.ValidationError
and throwMyOwnCustomValidationError
which can be handled by thecustom_exception_handler
What foreseeable design or maintenance problems does anyone see in this, if any? For example, if a new
APIException
is introduced into a future version of the framework and if that is not handled by mycustom_exception_handler
then that could be a problem. However, once discovered handling that should be pretty straight forward.Thank you for any insights into this design choice.
Beta Was this translation helpful? Give feedback.
All reactions