Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sanic-org/sanic into issue2986
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Dec 16, 2024
2 parents 515198b + 665234d commit d6e0ee9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sanic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def __init__(
status_code = status_code or getattr(
self.__class__, "status_code", None
)
quiet = quiet or getattr(self.__class__, "quiet", None)
quiet = (
quiet
if quiet is not None
else getattr(self.__class__, "quiet", None)
)
headers = headers or getattr(self.__class__, "headers", {})
if message is None:
message = self.message
Expand Down
15 changes: 15 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ class CustomError(SanicException):
assert SanicException("").message == ""


def test_exception_quiet_attribute():
class SilentException(SanicException):
quiet = True

class NoisyException(SanicException):
quiet = False

assert SilentException().quiet
assert not NoisyException().quiet
assert SilentException(quiet=True).quiet
assert NoisyException(quiet=True).quiet
assert not SilentException(quiet=False).quiet
assert not NoisyException(quiet=False).quiet


def test_request_middleware_exception_on_404(app: Sanic):
"""See https://github.com/sanic-org/sanic/issues/2950"""
counter = count()
Expand Down

0 comments on commit d6e0ee9

Please sign in to comment.