Coverage for seedboxsync/front/views/error.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-26 17:14 +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 view for errors.""" 

8 

9from flask import render_template 

10from werkzeug.exceptions import HTTPException 

11from seedboxsync.front.babel import gettext as _ 

12 

13 

14def error(e: Exception) -> tuple[str, int | None]: 

15 """ 

16 Global error handler. 

17 

18 Args: 

19 e (Exception): The exception. 

20 

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 _("Internal Server Error") 

26 detail = e.description if isinstance(e, HTTPException) else str(e) 

27 

28 return render_template("error.html", title=title, detail=detail), status_code