uncia/uncia/errors.py
2020-10-10 23:47:08 -04:00

34 lines
946 B
Python

import traceback
from sanic import response
from .log import logging
from .templates import error
def logstr(request, status, e=False):
if e:
logging.error(e)
uagent = request.headers.get('user-agent')
logging.info(f'{request.remote_addr} "{request.method} {request.path}" {status} "{uagent}"')
def not_found(request, exception):
return error(request, f'Not found: {request.path}', 404)
def method_not_supported(request, exception):
return error(request, f'Invalid method: {request.method}', 405)
def server_error(request, exception):
logstr(request, 500, e=exception)
msg = 'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!'
return error(request, msg, 500)
def no_template(request, exception):
logstr(request, 500, e=exception)
msg = 'I\'m a dumbass and forgot to create a template for this page'
return error(request, msg, 500)