Skip to content

Commit

Permalink
fix(ESSNTL-5422): Improve error message (#1506)
Browse files Browse the repository at this point in the history
* fix(ESSNTL-5422): Improve error message

Improving error messages on staleness endpoint

Signed-off-by: Fellipe Henrique <[email protected]>

* Applying requested changes

Signed-off-by: Fellipe Henrique <[email protected]>

---------

Signed-off-by: Fellipe Henrique <[email protected]>
  • Loading branch information
fellipeh authored Sep 28, 2023
1 parent 3909e11 commit 90bd2c1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions api/staleness.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ def create_staleness(body):
if not get_flag_value(FLAG_INVENTORY_CUSTOM_STALENESS):
return Response(None, status.HTTP_501_NOT_IMPLEMENTED)

current_identity = get_current_identity()
org_id = current_identity.org_id

# Validate account staleness input data
try:
validated_data = StalenessSchema().load(body)
Expand All @@ -107,9 +104,9 @@ def create_staleness(body):

log_create_staleness_succeeded(logger, created_staleness.id)
except IntegrityError:
error_message = f"An account staleness with org_id {org_id} already exists."
error_message = f"Staleness record for org_id {get_current_identity().org_id} already exists."

log_create_staleness_failed(logger, org_id)
log_create_staleness_failed(logger, get_current_identity().org_id)
logger.exception(error_message)
return json_error_response("Integrity error", error_message, status.HTTP_400_BAD_REQUEST)

Expand All @@ -127,7 +124,10 @@ def delete_staleness():
remove_staleness()
return flask_json_response(None, status.HTTP_204_NO_CONTENT)
except NoResultFound:
abort(status.HTTP_404_NOT_FOUND, "Account Staleness not found.")
abort(
status.HTTP_404_NOT_FOUND,
f"Staleness record for org_id {get_current_identity().org_id} does not exist.",
)


@api_operation
Expand All @@ -149,4 +149,7 @@ def update_staleness(body):

return flask_json_response(serialize_staleness_response(updated_staleness), status.HTTP_200_OK)
except NoResultFound:
abort(status.HTTP_404_NOT_FOUND, "Account Staleness not found.")
abort(
status.HTTP_404_NOT_FOUND,
f"Staleness record for org_id {get_current_identity().org_id} does not exist.",
)

0 comments on commit 90bd2c1

Please sign in to comment.