error.py 874 B

1234567891011121314151617181920212223242526
  1. from pathlib import Path
  2. from typing import Union
  3. from nicegui import ui
  4. def error_content(status_code: int, exception: Union[str, Exception] = '') -> None:
  5. if 400 <= status_code <= 499:
  6. title = "This page doesn't exist."
  7. elif 500 <= status_code <= 599:
  8. title = 'Server error'
  9. else:
  10. title = 'Unknown error'
  11. if isinstance(exception, str):
  12. message = exception
  13. else:
  14. message = exception.__class__.__name__
  15. if str(exception):
  16. message += ': ' + str(exception)
  17. with ui.column().classes('w-full py-20 items-center gap-0'):
  18. ui.html((Path(__file__).parent / 'static' / 'sad_face.svg').read_text()).classes('w-32 py-5')
  19. ui.label(str(status_code)).classes('text-6xl py-5')
  20. ui.label(title).classes('text-xl py-5')
  21. ui.label(message).classes('text-lg text-gray-500')