Skip to content

Commit

Permalink
BCOL API errors have different format than internal exceptions, so we… (
Browse files Browse the repository at this point in the history
  • Loading branch information
bolyachevets authored Oct 18, 2024
1 parent a590c00 commit 0e00cd4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion auth-api/src/auth_api/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
10 changes: 10 additions & 0 deletions auth-api/src/auth_api/exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
6 changes: 3 additions & 3 deletions auth-api/src/auth_api/services/validators/bcol_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,9 +38,9 @@ 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))
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
Expand Down

0 comments on commit 0e00cd4

Please sign in to comment.