import random
from fastapi.responses import HTMLResponse
from server import config, transponder_code_correlation, url_correlation
from server.services.jinja import base_template, error_template
from server.utils.logger_trace import trace
from server.utils.notify import send_message
# ChatGPT promt: Make this text more Humoristic in one sentenced text, 15 different with emojies as Python list: Sorry to hear that but we have some problem
ERROR_MSG_LIST = [
"Sorry to hear that, but we've got a problem that's bigger than my inability to resist a donut! π©",
"Apologies for the inconvenience, but we've hit a snag - it's not as funny as my cat chasing its tail, but it's a problem nonetheless! π±",
"Sorry to hear that, but we've encountered a problem - it's not as entertaining as a clown at a circus, but it's there! πͺ",
"Oops! We've stumbled upon a problem, but don't worry, it's not as disastrous as my cooking! π³",
"Sorry to hear that, but we've got a problem that's more stubborn than a mule on a Monday morning! π΄",
"Apologies, but we've run into a problem - it's not as amusing as my grandma's dance moves, but it's a problem! π΅π",
"Sorry to hear that, but we've got a problem that's more tangled than my headphone wires! π§",
"Oops! We've hit a problem, but don't worry, it's not as catastrophic as my last blind date! π",
"Sorry to hear that, but we've got a problem that's more elusive than a sock in a washing machine! π§¦",
"Apologies, but we've run into a problem - it's not as hilarious as my attempt at yoga, but it's a problem! π§ββοΈ",
"Sorry to hear that, but we've got a problem that's more confusing than a chameleon in a bag of Skittles! π¦π",
"Oops! We've encountered a problem, but don't worry, it's not as disastrous as my attempt at karaoke! π€",
"Sorry to hear that, but we've got a problem that's more stubborn than a toddler refusing to eat their veggies! πΆπ₯¦",
"Apologies, but we've run into a problem - it's not as amusing as my dog trying to catch its tail, but it's a problem! πΆ",
"Sorry to hear that, but we've got a problem that's more elusive than the end of a rainbow! π",
]
@trace
async def generate_error(error_msg: str = None, title: str = "Error", status_code: int = 500, quiet: bool = False):
if not error_msg:
error_msg = random.choice(ERROR_MSG_LIST)
if not quiet:
send_message(f"π Error while processing url: {url_correlation.get()}, transponder_code: {transponder_code_correlation.get()}, error: {error_msg}")
error_template_rendered = await error_template.render_async(error_msg=error_msg, transponder_code=transponder_code_correlation.get())
base_context = {
"enable_ads_header": config.ENABLE_ADS_BANNER,
"body_template": error_template_rendered,
"title": title,
}
base_template_rendered = await base_template.render_async(base_context, HOST_ADDRESS=config.HOST_ADDRESS)
return HTMLResponse(base_template_rendered, status_code=status_code)