Module for translating JSON decoding errors into user-friendly Russian messages.
This module provides a utility class that converts Python's JSONDecodeError
exceptions into more descriptive and readable error messages in Russian.
It is useful for improving the end-user experience when parsing JSON data.
JSONDecodeErrorTranslator
Translates JSONDecodeError messages into user-friendly Russian descriptions.
This class provides a method to convert Python's JSONDecodeError exceptions into more readable error messages for end users.
translate
classmethod
translate(
error: JSONDecodeError,
*,
msg: str = BASE_JSON_ERROR_MESSAGE,
line_number: int | None = None,
) -> str
Translate a JSONDecodeError into a human-readable message in Russian.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Example
try:
json.loads('{"name": "Alice",}')
except JSONDecodeError as e:
print(DecodeErrorTranslator.translate(e))
#> Ошибка конвертации в формате JSON.
#> Позиция: 16.
#> Описание: не правильно используются двойные кавычки.