Skip to content

Commit

Permalink
Fix error reporting during the config flow
Browse files Browse the repository at this point in the history
It was not showing the error received from the api properly,
it crashed instead
  • Loading branch information
NLthijs48 committed Apr 19, 2024
1 parent 1264957 commit 30f9ac8
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions custom_components/crisp/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
CrispApiClientCommunicationError,
CrispApiClientError,
)
from .const import DOMAIN
import logging

_LOGGER = logging.getLogger(__name__)
from .const import DOMAIN, LOGGER


class CrispConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand Down Expand Up @@ -53,20 +50,20 @@ async def async_step_user(
response = await self.crisp_client.request_login_code(
email=user_input[CONF_EMAIL], country=country
)
_LOGGER.debug("request_login_code response: ", response)
LOGGER.debug("request_login_code response: %s", response)
except CrispApiClientAuthenticationError as exception:
_LOGGER.warning(exception)
LOGGER.warning(exception)
errors["base"] = "auth"
except CrispApiClientCommunicationError as exception:
_LOGGER.error(exception)
LOGGER.error(exception)
errors["base"] = "connection"
except CrispApiClientError as exception:
_LOGGER.exception(exception)
LOGGER.exception(exception)
errors["base"] = "unknown"
else:
# Error from the api, email not found or something like that
if "error" in response:
errors["email"] = response.error
errors["email"] = response["error"]
else:
# Save the email/client_id
self.user_info = user_input
Expand Down Expand Up @@ -109,20 +106,20 @@ async def async_step_login(self, user_input: dict | None = None):
country=self.user_info[CONF_COUNTRY_CODE],
login_code=user_input[CONF_CODE],
)
_LOGGER.debug("login response: ", response)
LOGGER.debug("login response: %s", response)
except CrispApiClientAuthenticationError as exception:
_LOGGER.warning(exception)
LOGGER.warning(exception)
errors["base"] = "auth"
except CrispApiClientCommunicationError as exception:
_LOGGER.error(exception)
LOGGER.error(exception)
errors["base"] = "connection"
except CrispApiClientError as exception:
_LOGGER.exception(exception)
LOGGER.exception(exception)
errors["base"] = "unknown"
else:
if "error" in response:
# These errors are not super human-readable, could attempt to map some of them to better text
errors[CONF_CODE] = response.error
errors[CONF_CODE] = "Could not login: " + response["error"]
elif "id" not in response:
# Did not get a user id back as confirmation, something went wrong
errors["base"] = "Unknown error, could not login"
Expand Down

0 comments on commit 30f9ac8

Please sign in to comment.