Skip to content

Commit

Permalink
Avoid using static exceptions for better debugging experience (#3529)
Browse files Browse the repository at this point in the history
Before this change:

```
AbstractErrorWebExceptionHandler : [0861a0da-1]  500 Server Error for HTTP POST "/"

reactor.netty.http.server.RequestTimeoutException: null
```

After this change:

```
AbstractErrorWebExceptionHandler : [dbf4f5fb-1]  500 Server Error for HTTP POST "/"

reactor.netty.http.server.RequestTimeoutException: Request timed out
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
	*__checkpoint ⇢ Handler com.example.MyController#hello(ServerHttpRequest) [DispatcherHandler]
	*__checkpoint ⇢ HTTP POST "/" [ExceptionHandlingWebHandler]
Original Stack Trace:
```
  • Loading branch information
violetagg authored Dec 2, 2024
1 parent 6e70340 commit 864474a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ final class RequestTimeoutTask implements Runnable {
@SuppressWarnings("FutureReturnValueIgnored")
public void run() {
if (!requestAvailable) {
ctx.fireExceptionCaught(RequestTimeoutException.INSTANCE);
ctx.fireExceptionCaught(RequestTimeoutException.requestTimedOut());
//"FutureReturnValueIgnored" this is deliberate
ctx.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ final class RequestTimeoutTask implements Runnable {
@SuppressWarnings("FutureReturnValueIgnored")
public void run() {
if (ctx.channel().isActive() && !(isInboundCancelled() || isInboundDisposed())) {
onInboundError(RequestTimeoutException.INSTANCE);
onInboundError(RequestTimeoutException.requestTimedOut());
//"FutureReturnValueIgnored" this is deliberate
ctx.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2023-2024 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,17 +18,20 @@
import io.netty.channel.ChannelException;

final class RequestTimeoutException extends ChannelException {

static final RequestTimeoutException INSTANCE = new RequestTimeoutException();
static final String REQUEST_TIMED_OUT = "Request timed out";

private static final long serialVersionUID = 422626851161276356L;

RequestTimeoutException() {
super(null, null, true);
RequestTimeoutException(String message) {
super(message);
}

@Override
public synchronized Throwable fillInStackTrace() {
return this;
}

static RequestTimeoutException requestTimedOut() {
return new RequestTimeoutException(REQUEST_TIMED_OUT);
}
}

0 comments on commit 864474a

Please sign in to comment.