Coverage for seedboxsync/front/views/error.py: 100%
8 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""SeedboxSync Flask vierw for errors."""
9from flask import render_template
10from flask_babel import gettext
11from werkzeug.exceptions import HTTPException
14def error(e: Exception) -> tuple[str, int | None]:
15 """
16 Global error handler.
18 Args:
19 e (Exception): The exception.
21 Returns:
22 str: Rendered error template with status code.
23 """
24 status_code = e.code if isinstance(e, HTTPException) else 500
25 title = e.name if isinstance(e, HTTPException) else gettext("Internal Server Error")
26 detail = e.description if isinstance(e, HTTPException) else str(e)
28 return render_template("error.html", title=title, detail=detail), status_code