Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial orjson support take 3 #73849

Merged
merged 16 commits into from
Jun 22, 2022
Prev Previous commit
Next Next commit
DRY
  • Loading branch information
bdraco committed Jun 15, 2022
commit b632e4c92d8b977034e25768cfe79c2463f3753a
4 changes: 2 additions & 2 deletions homeassistant/components/http/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from homeassistant import exceptions
from homeassistant.const import CONTENT_TYPE_JSON
from homeassistant.core import Context, is_callback
from homeassistant.helpers.json import json_bytes
from homeassistant.helpers.json import JSON_ENCODE_EXCEPTIONS, json_bytes

from .const import KEY_AUTHENTICATED, KEY_HASS

Expand Down Expand Up @@ -53,7 +53,7 @@ def json(
"""Return a JSON response."""
try:
msg = json_bytes(result)
except (UnicodeEncodeError, ValueError, TypeError) as err:
except JSON_ENCODE_EXCEPTIONS as err:
_LOGGER.error("Unable to serialize to JSON: %s\n%s", err, result)
raise HTTPInternalServerError from err
response = web.Response(
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/helpers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import orjson

JSON_ENCODE_EXCEPTIONS = (UnicodeEncodeError, TypeError, ValueError)


class JSONEncoder(json.JSONEncoder):
"""JSONEncoder that supports Home Assistant objects."""
Expand Down