Skip to content

Conversation

@robin-nitrokey
Copy link
Member

Previously, we only showed the custom error message for the returned error code if there is one. This can be confusing if the custom error message does not match the error returned by the NetHSM. This patch always adds the NetHSM error message to the error returned by the API.

body = json.loads(e.api_response.response.data)
if body is not None and "message" in body:
message += "\n" + body["message"]
message += "\nNetHSM error message: " + body["message"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check in the NetHSM code, that it always uses a "message" field? Otherwise I maybe would just dump the whole body.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not perform an exhaustive search but I’ve never seen a case where it returned something else.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and in fact we only return the error JSON for "400 Bad request" and for "412 Precondition Failed", however in the second case without useful information. And in these cases it is always of that format. So all good.

Copy link
Collaborator

@ansiwen ansiwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robin-nitrokey robin-nitrokey mentioned this pull request Oct 15, 2025
Previously, we only showed the custom error message for the returned
error code if there is one.  This can be confusing if the custom error
message does not match the error returned by the NetHSM.  This patch
always adds the NetHSM error message to the error returned by the API.
@robin-nitrokey robin-nitrokey merged commit 95cd118 into main Oct 15, 2025
16 checks passed
@robin-nitrokey robin-nitrokey deleted the error branch October 15, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants