You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
When handling failed requests (such as HTTP 4xx or 5xx responses), the responseBodyEnd callback is invoked with a byteCount of 0, even if the server includes a response body containing error details. This happens regardless of whether the response body is empty or contains information like error messages or stack traces.
I have set up a custom retry interceptor that retries the request up to two times. The backend API returns an HTTP 500 error for the first two attempts and a successful HTTP 200 response for the final retry. However, I noticed that when the backend returns a 500 error, the responseBodyEnd callback always reports a byteCount of 0, even though the body contains error details. On successful (HTTP 200) responses, the byteCount is non-zero, as expected.
Is this expected behavior? As per my understanding the byteCount should reflect the size of the body, even for error responses.
Below is the sample code snippets - Backend API (Express):
const internalError = catchAsync(async (req: Request, res: Response) => {
const retryCount = parseInt(req.headers["x-retry-count"] as string) || 0;
if (retryCount >= 3) {
res.status(200).json({ message: "Success after 3 retries!" });
} else {
res.status(500).json({ message: "Something went wrong on the server." });
}
});
Here is the custom retry interceptor I am using to retry the request up to two times:
class RetryInterceptor : Interceptor {
private val maxRetryCount = 3
private val retryDelayMillis = 500L
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
var attempt = 0
var lastException: IOException? = null
var response: Response? = null
do {
attempt++
try {
val modifiedRequest = chain.request().newBuilder()
.addHeader("X-Retry-Count", attempt.toString())
.build()
response = chain.proceed(modifiedRequest)
if (response.isSuccessful) {
return response
}
} catch (e: IOException) {
lastException = e
}
// we need to close the response before retrying the request again
response?.close()
if (attempt < maxRetryCount) {
try {
TimeUnit.MILLISECONDS.sleep(attempt * retryDelayMillis)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}
} while (attempt < maxRetryCount)
throw lastException ?: IOException("Unknown error after $maxRetryCount retries")
}
The text was updated successfully, but these errors were encountered:
Description:
When handling failed requests (such as HTTP 4xx or 5xx responses), the
responseBodyEnd
callback is invoked with abyteCount
of 0, even if the server includes a response body containing error details. This happens regardless of whether the response body is empty or contains information like error messages or stack traces.I have set up a custom retry interceptor that retries the request up to two times. The backend API returns an HTTP 500 error for the first two attempts and a successful HTTP 200 response for the final retry. However, I noticed that when the backend returns a
500
error, theresponseBodyEnd
callback always reports abyteCount
of 0, even though the body contains error details. On successful (HTTP 200) responses, thebyteCount
is non-zero, as expected.Is this expected behavior? As per my understanding the
byteCount
should reflect the size of the body, even for error responses.Below is the sample code snippets -
Backend API (Express):
Here is the custom retry interceptor I am using to retry the request up to two times:
The text was updated successfully, but these errors were encountered: