mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-02-22 16:51:59 +00:00
19 lines
680 B
Python
19 lines
680 B
Python
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
|