我已经编写了一个自定义异常处理类来验证输入请求数据,并在验证失败时引发它。这是一个烧瓶应用程序。直到时间服务器还没有发送响应之前,这似乎一直在工作,因为我可以看到异常对象有一个自定义错误,但随后它被转换为一个通用的500错误消息。我是不是错过了什么?你做错了什么?你知道吗
class CustException(Exception):
pass
class APIException(CustException):
def __init__(self, status=None, title=None, type=None, detail=None, **kwargs):
super(AIVException, self).__init__(detail)
self.status = status
self.detail = detail
self.title = title
self.type = type
if x not in [1, 2]:
raise APIException(status=400, title='Bad request', type=default_type, detail="pass the correct value")
**
Note - I want this to do by raising an exception instead of using error handler. So please don't mark it duplicate.
**
如果要使用APIException返回自定义消息或其他内容,可以使用errorhandler装饰器
相关问题 更多 >
编程相关推荐