exceptions: Accept lazy translation as JsonableError argument.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-02-03 14:52:46 -08:00 committed by Anders Kaseorg
parent b4ee94e758
commit b85cb1e700
1 changed files with 4 additions and 3 deletions

View File

@ -1,8 +1,9 @@
from enum import Enum, auto
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple, Union
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
from django_stubs_ext import StrPromise
class ErrorCode(Enum):
@ -85,9 +86,9 @@ class JsonableError(Exception):
# like 403 or 404.
http_status_code: int = 400
def __init__(self, msg: str) -> None:
def __init__(self, msg: Union[str, StrPromise]) -> None:
# `_msg` is an implementation detail of `JsonableError` itself.
self._msg: str = msg
self._msg = msg
@staticmethod
def msg_format() -> str: