Skip to content

Commit

Permalink
add data field to message in case of invalid params
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <[email protected]>
  • Loading branch information
macfarla committed Mar 20, 2023
1 parent 48e2063 commit 3ba9224
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public JsonRpcResponse process(
try {
return method.response(request);
} catch (final InvalidJsonRpcParameters e) {
JsonRpcError invalidParamsError = JsonRpcError.INVALID_PARAMS;
invalidParamsError.setData(e.getMessage());
LOG.debug("Invalid Params for method: {}", method.getName(), e);
return new JsonRpcErrorResponse(id, JsonRpcError.INVALID_PARAMS);
return new JsonRpcErrorResponse(id, invalidParamsError);
} catch (final MultiTenancyValidationException e) {
return new JsonRpcUnauthorizedResponse(id, JsonRpcError.UNAUTHORIZED);
} catch (final RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -261,9 +262,13 @@ private void checkResponse(
// Check error
if (expectedResponse.has("error")) {
assertThat(responseBody.has("error")).isTrue();
final String expectedError = expectedResponse.get("error").toString();
final String actualError = responseBody.get("error").toString();
assertThat(actualError).isEqualToIgnoringWhitespace(expectedError);

final JsonNode expectedErrorJson = expectedResponse.get("error");
final JsonNode actualErrorJson = responseBody.get("error");

// ignore data field, it's only used to provide extra error info for INVALID_PARAMS
assertThat(actualErrorJson.get("code")).isEqualTo(expectedErrorJson.get("code"));
assertThat(actualErrorJson.get("message")).isEqualTo(expectedErrorJson.get("message"));
}
}

Expand Down

0 comments on commit 3ba9224

Please sign in to comment.