Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Fix Netty uncaught exception handling #3791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,27 @@ public void commit() {

@Override
public void failure(Throwable error) {
ctx.writeAndFlush(new DefaultFullHttpResponse(req.protocolVersion(), HttpResponseStatus.INTERNAL_SERVER_ERROR))
.addListener(ChannelFutureListener.CLOSE);
try {
ctx.writeAndFlush(new DefaultFullHttpResponse(req.protocolVersion(), HttpResponseStatus.INTERNAL_SERVER_ERROR))
.addListener(ChannelFutureListener.CLOSE);
} catch (Throwable t) {
error.addSuppressed(t);
} finally {
rethrow(error);
}
}

/**
* Rethrow the original exception as required by JAX-RS, 3.3.4
*
* @param error throwable to be re-thrown
*/
private void rethrow(Throwable error) {
if (error instanceof RuntimeException) {
throw (RuntimeException) error;
} else {
throw new ContainerException(error);
}
}

@Override
Expand Down