20 lines
647 B
Python
20 lines
647 B
Python
class ApiError(Exception):
|
|
def __init__(self, status, code, message, headers=None):
|
|
self.status = status
|
|
self.code = code
|
|
self.message = message
|
|
self.headers = headers or {}
|
|
|
|
|
|
def invalid():
|
|
return ApiError(400, 'invalid_request', 'Неверный запрос')
|
|
|
|
|
|
def unauthorized(basic=False):
|
|
scheme = 'Basic realm="messenger", charset="UTF-8"' if basic else 'Bearer realm="messenger"'
|
|
return ApiError(401, 'unauthorized', 'Требуется аутентификация', {'WWW-Authenticate': scheme})
|
|
|
|
|
|
def not_found():
|
|
return ApiError(404, 'not_found', 'Объект не найден')
|