You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
842 B
22 lines
842 B
from rest_framework.views import exception_handler |
|
|
|
|
|
def my_exception_handler(exc, context): |
|
response = exception_handler(exc, context) |
|
print('exception_handler') |
|
print(exception_handler) |
|
if response is not None: |
|
response.data['code'] = response.status_code |
|
if response.status_code == 405: |
|
response.data['msg'] = '请求不予许' |
|
elif response.status_code == 401: |
|
response.data['msg'] = '认证未通过' |
|
elif response.status_code == 403: |
|
response.data['msg'] = '禁止访问' |
|
elif response.status_code == 404: |
|
response.data['msg'] = '未找到文件' |
|
elif response.status_code >= 500: |
|
response.data['msg'] = '服务器异常' |
|
else: |
|
response.data['msg'] = '其他未知错误' |
|
return response
|
|
|