Skip to content

Commit

Permalink
Use exc_type_str instead of exc_type.__name__
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Aug 6, 2024
1 parent bd9bf48 commit ad7a72b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions starlette/middleware/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import html
import inspect
import sys
import traceback
import typing

Expand Down Expand Up @@ -237,11 +238,13 @@ def generate_html(self, exc: Exception, limit: int = 7) -> str:
exc_html += self.generate_frame_html(frame, is_collapsed)
is_collapsed = True

if sys.version_info >= (3, 13): # pragma: no cover
exc_type_str = traceback_obj.exc_type_str
else: # pragma: no cover
exc_type_str = traceback_obj.exc_type.__name__

# escape error class and text
error = (
f"{html.escape(traceback_obj.exc_type.__name__)}: "
f"{html.escape(str(traceback_obj))}"
)
error = f"{html.escape(exc_type_str)}: {html.escape(str(traceback_obj))}"

return TEMPLATE.format(styles=STYLES, js=JS, error=error, exc_html=exc_html)

Expand Down

0 comments on commit ad7a72b

Please sign in to comment.