diff --git a/auth-api/src/auth_api/exceptions/__init__.py b/auth-api/src/auth_api/exceptions/__init__.py index ac7bdb4fc2..01b466c517 100644 --- a/auth-api/src/auth_api/exceptions/__init__.py +++ b/auth-api/src/auth_api/exceptions/__init__.py @@ -9,4 +9,9 @@ from auth_api.exceptions.errors import Error # noqa: I001, I003 from auth_api.exceptions.exception_handler import ExceptionHandler -from auth_api.exceptions.exceptions import BusinessException, CustomException, ServiceUnavailableException +from auth_api.exceptions.exceptions import ( + BCOLException, + BusinessException, + CustomException, + ServiceUnavailableException, +) diff --git a/auth-api/src/auth_api/exceptions/exceptions.py b/auth-api/src/auth_api/exceptions/exceptions.py index 599cf9848e..624db39304 100644 --- a/auth-api/src/auth_api/exceptions/exceptions.py +++ b/auth-api/src/auth_api/exceptions/exceptions.py @@ -34,6 +34,16 @@ def __init__(self, error, *args, **kwargs): self.status_code = Error.SERVICE_UNAVAILABLE.name +class BCOLException(Exception): # noqa: N818 + """Exception for BCOL API errors.""" + + def __init__(self, message, status_code): + """Return when error object is coming from BCOL API.""" + self.message = message + self.status_code = status_code + self.name = "BCOL API Error" + + class CustomException: """A custom exception object to be used propagate errors.""" diff --git a/auth-api/src/auth_api/services/validators/bcol_credentials.py b/auth-api/src/auth_api/services/validators/bcol_credentials.py index b5a5db4e50..e4f4ca7795 100644 --- a/auth-api/src/auth_api/services/validators/bcol_credentials.py +++ b/auth-api/src/auth_api/services/validators/bcol_credentials.py @@ -17,7 +17,7 @@ from flask import current_app -from auth_api.exceptions import BusinessException, Error +from auth_api.exceptions import BCOLException, BusinessException, Error from auth_api.services.rest_service import RestService from auth_api.services.validators.validator_response import ValidatorResponse from auth_api.utils.user_context import UserContext, user_context @@ -38,9 +38,10 @@ def validate(is_fatal=False, **kwargs) -> ValidatorResponse: ) if bcol_response.status_code != HTTPStatus.OK: error = json.loads(bcol_response.text) - validator_response.add_error(BusinessException(error["detail"], bcol_response.status_code)) + # error_formatted = {"name": "BCOL API call error", "message": error} + validator_response.add_error(BCOLException(error, bcol_response.status_code)) if is_fatal: - raise BusinessException(error["detail"], bcol_response.status_code) + raise BCOLException(error, bcol_response.status_code) else: bcol_account_number = bcol_response.json().get("accountNumber") from auth_api.services.org import Org as OrgService # pylint:disable=cyclic-import, import-outside-toplevel