Skip to content

Commit

Permalink
Delays logging of error message when invalid JSON content is fetched
Browse files Browse the repository at this point in the history
For some calls it may not be easy to determine if it contains a JSON body or we want to try to access it anyway.
With this change the caller can decide whether to log the thrown exception or not.

Fixes: OX-10862
  • Loading branch information
sabieber committed Mar 20, 2024
1 parent a8835ff commit 0d19e75
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/sirius/web/http/WebContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1954,26 +1954,26 @@ public StructuredInput getXMLContent(boolean namespaceAware) {
public ObjectNode getJSONContent() {
try {
if (content == null) {
throw Exceptions.handle()
throw Exceptions.createHandled()
.to(WebServer.LOG)
.withSystemErrorMessage("Expected a valid JSON map as body of this request.")
.handle();
}
if (!content.isInMemory()
&& content.getFile().length() > maxStructuredInputSize
&& maxStructuredInputSize > 0) {
throw Exceptions.handle()
throw Exceptions.createHandled()
.to(WebServer.LOG)
.withSystemErrorMessage(
"Request body is too large to parse as JSON. The limit is %d bytes",
"Request body is too large to parse as JSON. The limit is %d bytes.",
maxStructuredInputSize)
.handle();
}
return Json.parseObject(content.getString(getRequestEncoding()));
} catch (HandledException exception) {
throw exception;
} catch (Exception exception) {
throw Exceptions.handle()
throw Exceptions.createHandled()
.to(WebServer.LOG)
.error(exception)
.withSystemErrorMessage("Expected a valid JSON map as body of this request: %s (%s).")
Expand Down

0 comments on commit 0d19e75

Please sign in to comment.