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.
		
		
		
		
			
				
					23 lines
				
				842 B
			
		
		
			
		
	
	
					23 lines
				
				842 B
			| 
											2 years ago
										 | 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
 |