Skip to content

Commit

Permalink
fix: reduce log level when unable to read from cached request
Browse files Browse the repository at this point in the history
This is normal for GET requests and should not cause panic attacks when reading the logs.
  • Loading branch information
fengelniederhammer authored and JonasKellerer committed Jan 23, 2024
1 parent 194e7fd commit 6810696
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import jakarta.servlet.ServletInputStream
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletRequestWrapper
import mu.KotlinLogging
import org.springframework.http.HttpMethod
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
Expand Down Expand Up @@ -57,15 +58,17 @@ class CachedBodyHttpServletRequest(request: HttpServletRequest, val objectMapper
}

if (contentLength == 0) {
log.warn { "Could not read from request body, because content length is 0." }
log.debug { "Could not read from request body, because content length is 0." }
return emptyMap()
}

return try {
objectMapper.readValue(inputStream)
} catch (exception: Exception) {
log.error { "Failed to read from request body: ${exception.message}" }
log.debug { exception.stackTraceToString() }
if (method != HttpMethod.GET.name()) {
log.warn { "Failed to read from request body: ${exception.message}, contentLength $contentLength" }
log.debug { exception.stackTraceToString() }
}
emptyMap()
}
}
Expand Down

0 comments on commit 6810696

Please sign in to comment.