在Django中间件中正确处理异常有一个问题。 我的例外:
from rest_framework.exceptions import APIException
from rest_framework.status import HTTP_403_FORBIDDEN
class MyProfileAuthorizationError(APIException):
def __init__(self, msg):
APIException.__init__(self, msg)
self.status_code = HTTP_403_FORBIDDEN
self.message = msg
以及我的中间件:
^{pr2}$这个异常抛出500而不是403。我该怎么解决呢?
尝试以下例外情况:
我想你不能这么做,读这个:https://groups.google.com/forum/#!topic/django-developers/-ncPqVzF8W8
尝试返回^{} 响应,而不是引发异常
我认为您应该使用^{} ,而不是使用中间件:
并将其添加到^{} 中,使其可用于每个API视图。在
^{pr2}$相关问题 更多 >
编程相关推荐