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

BCOL API errors have different format than internal exceptions, so we… #3081

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading