Skip to content

Commit

Permalink
Clean up default error message handling
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Sep 20, 2023
1 parent d969e86 commit 956b8f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions oidc-controller/api/core/http_exception_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

logger = structlog.getLogger(__name__)

CONFLICT_DEFAULT_MSG = "The requested resource already exists"
NOT_FOUND_DEFAULT_MSG = "The requested resource wasn't found"
UNKNOWN_DEFAULT_MSG = "The server was unable to process the request"

def raise_appropriate_http_exception(err: WriteError, exists_msg: str = None):
def raise_appropriate_http_exception(err: WriteError, exists_msg: str = CONFLICT_DEFAULT_MSG):
if err.code == 11000:
raise HTTPException(
status_code=http_status.HTTP_409_CONFLICT,
Expand All @@ -16,14 +19,11 @@ def raise_appropriate_http_exception(err: WriteError, exists_msg: str = None):
logger.error("Unknown error", err=err)
raise HTTPException(
status_code=http_status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="The server was unable to process the request",
detail=UNKNOWN_DEFAULT_MSG,
)


def check_and_raise_not_found_http_exception(resp, detail: str = None):
if detail is None:
detail = "The requested resource wasn't found"

def check_and_raise_not_found_http_exception(resp, detail: str = NOT_FOUND_DEFAULT_MSG):
if resp is None:
raise HTTPException(
status_code=http_status.HTTP_404_NOT_FOUND,
Expand Down
2 changes: 1 addition & 1 deletion oidc-controller/api/verificationConfigs/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def create(self, ver_config: VerificationConfig) -> VerificationConfig:
ver_confs.insert_one(jsonable_encoder(ver_config))
except Exception as err:
raise_appropriate_http_exception(
err, exists_msg="Verification configuration already exists")
err, exists_msg="Verifier configuration already exists")
return ver_confs.find_one({"ver_config_id": ver_config.ver_config_id})

async def get(self, ver_config_id: str) -> VerificationConfig:
Expand Down

0 comments on commit 956b8f9

Please sign in to comment.