Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle invalid Json bad request body in PostStateValidators #7739

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

courtneyeh
Copy link
Contributor

#7670

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

Comment on lines +84 to +94
try {
requestBody = request.getOptionalRequestBody();
} catch (RuntimeException e) {
final Throwable throwable = Throwables.getRootCause(e);
if (throwable instanceof JsonParseException) {
request.respondError(SC_BAD_REQUEST, throwable.getMessage());
} else {
throw e;
}
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try {
requestBody = request.getOptionalRequestBody();
} catch (RuntimeException e) {
final Throwable throwable = Throwables.getRootCause(e);
if (throwable instanceof JsonParseException) {
request.respondError(SC_BAD_REQUEST, throwable.getMessage());
} else {
throw e;
}
return;
}
try {
requestBody = request.getOptionalRequestBody();
} catch (JsonProcessingException e) {
final Throwable throwable = Throwables.getRootCause(e);
request.respondError(SC_BAD_REQUEST, throwable.getMessage());
return;
} catch (RuntimeException e) {
throw e;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would not work because the exception is a RuntimeException, but the root cause of the exception is a JsonProcessingException. So cannot just catch the JsonProcessingException as you have.

Copy link
Member

@lucassaldanha lucassaldanha Nov 21, 2023

Choose a reason for hiding this comment

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

I'll take a look later. Maybe there is something we can do on the getOptionalRequeatBody.

But it can be done in a separate PR, no need to block this.

Copy link
Member

@lucassaldanha lucassaldanha left a comment

Choose a reason for hiding this comment

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

LGTM. Just a nit suggestion when handling the exceptions.

@courtneyeh courtneyeh merged commit 982c442 into Consensys:master Nov 21, 2023
15 checks passed
@courtneyeh courtneyeh deleted the post-state-validators branch November 21, 2023 07:02
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.

2 participants