fediseer/overseer/exceptions.py

34 lines
924 B
Python
Raw Normal View History

2023-06-22 00:04:45 +00:00
from werkzeug import exceptions as wze
from loguru import logger
class BadRequest(wze.BadRequest):
def __init__(self, message, log=None):
self.specific = message
self.log = log
class Forbidden(wze.Forbidden):
def __init__(self, message, log=None):
self.specific = message
self.log = log
2023-06-22 00:32:08 +00:00
class Unauthorized(wze.Unauthorized):
def __init__(self, message, log=None):
self.specific = message
self.log = log
class NotFound(wze.NotFound):
def __init__(self, message, log=None):
self.specific = message
self.log = log
2023-06-22 00:04:45 +00:00
class Locked(wze.Locked):
def __init__(self, message, log=None):
self.specific = message
self.log = log
def handle_bad_requests(error):
'''Namespace error handler'''
if error.log:
logger.warning(error.log)
return({'message': error.specific}, error.code)