Skip to content

Commit

Permalink
BI-5139 Handle US read-only mode (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantAnxiety authored Dec 20, 2023
1 parent e365d04 commit 02a53cc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/dl_api_lib/dl_api_lib/app/control_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import flask
from flask import request
from flask_restx import Api
from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import (
BadRequest,
UnavailableForLegalReasons,
)

from dl_api_commons.access_control_common import AuthFailureError
from dl_api_commons.flask.middlewares.commit_rci_middleware import ReqCtxInfoMiddleware
Expand Down Expand Up @@ -41,6 +44,12 @@ def handle_us_error(error): # type: ignore
return {"message": text}, resp.status_code


@API.errorhandler(UnavailableForLegalReasons)
def handle_us_read_only_mode_error(error): # type: ignore
# flask_restx doesn't support HTTP 451, so we have to handle it manually
return error.data, 451


@API.errorhandler(BadRequest)
def handle_bad_request(error): # type: ignore
rci = ReqCtxInfoMiddleware.get_last_resort_rci()
Expand Down
1 change: 1 addition & 0 deletions lib/dl_api_lib/dl_api_lib/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
common_exc.USPermissionCheckError: 530,
common_exc.USLockUnacquiredException: status.LOCKED,
common_exc.USBadRequestException: status.BAD_REQUEST,
common_exc.USReadOnlyModeEnabledException: status.UNAVAILABLE_FOR_LEGAL_REASONS,
common_exc.USIncorrectTenantIdException: status.CONFLICT,
common_exc.QueryConstructorError: status.BAD_REQUEST,
common_exc.ResultRowCountLimitExceeded: status.BAD_REQUEST,
Expand Down
8 changes: 8 additions & 0 deletions lib/dl_core/dl_core/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ def message(self) -> str:
return "US permission check error"


class USReadOnlyModeEnabledException(USReqException):
err_code = USReqException.err_code + ["READ_ONLY"]

@property
def message(self) -> str:
return "The service is currently in read-only mode"


class USBadRequestException(USReqException):
err_code = USReqException.err_code + ["BAD_REQUEST"]

Expand Down
1 change: 1 addition & 0 deletions lib/dl_core/dl_core/united_storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def json(self) -> dict:
(409, re.compile("The entry already exists"), exc.USAlreadyExistsException),
(409, None, exc.USIncorrectTenantIdException),
(423, None, exc.USLockUnacquiredException),
(451, None, exc.USReadOnlyModeEnabledException),
(530, None, exc.USPermissionCheckError),
]

Expand Down

0 comments on commit 02a53cc

Please sign in to comment.