mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 09:50:05 +00:00
Initial commit
This commit is contained in:
18
api/exceptions.py
Normal file
18
api/exceptions.py
Normal file
@ -0,0 +1,18 @@
|
||||
from rest_framework.views import exception_handler
|
||||
from rest_framework.exceptions import Throttled
|
||||
|
||||
|
||||
def custom_exception_handler(exc, context):
|
||||
# Call REST framework's default exception handler first,
|
||||
# to get the standard error response.
|
||||
response = exception_handler(exc, context)
|
||||
|
||||
if isinstance(exc, Throttled): # check that a Throttled exception is raised
|
||||
custom_response_data = { # prepare custom response data
|
||||
"message": "Too many attemps. Please Try again in %d seconds." % exc.wait,
|
||||
}
|
||||
response.data = (
|
||||
custom_response_data # set the custom response data on response object
|
||||
)
|
||||
|
||||
return response
|
Reference in New Issue
Block a user