-
Notifications
You must be signed in to change notification settings - Fork 299
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
Conversation
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
#7670
Documentation
doc-change-required
label to this PR if updates are required.Changelog