Skip to content

Commit

Permalink
[CSAPI]: Preserve exception cause on invalid payload
Browse files Browse the repository at this point in the history
For some exceptions, the cause backtrace provides necessary details for
debugging the actual cause of the issue, since the message is not always
detailed enough.
  • Loading branch information
matthijskooijman committed Feb 1, 2024
1 parent 5ca3684 commit 5a70843
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public static InvalidRequestException badRequest(String msg)

public static InvalidRequestException invalidPayload(String msg)
{
return new InvalidRequestException(ErrorCode.BAD_PAYLOAD, msg);
return invalidPayload(msg, null);
}


public static InvalidRequestException invalidPayload(String msg, Throwable cause)
{
return new InvalidRequestException(ErrorCode.BAD_PAYLOAD, msg, cause);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ protected void create(final RequestContext ctx) throws IOException
}
catch (ResourceParseException e)
{
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage());
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage(), e);
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ protected void update(final RequestContext ctx, final String id) throws IOExcept
}
catch (ResourceParseException e)
{
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage());
throw ServiceErrors.invalidPayload("Invalid payload: " + e.getMessage(), e);
}

// update in datastore
Expand Down

0 comments on commit 5a70843

Please sign in to comment.