The Response Filter and Response Interceptor handle exceptions (#12722)

Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
huazhongming 2023-07-14 10:37:10 +08:00 committed by GitHub
parent 1c5265073b
commit 65491fda07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -121,16 +121,14 @@ public class ServiceInvokeRestFilter implements RestRequestFilter {
+ "\n message is: " + result.getException().getMessage()
+ "\n stacktrace is: " + stackTraceToString(exception));
}
} else {
try {
// invoke the intercept chain before Result write to response
executeResponseIntercepts(url, request, nettyHttpResponse, result.getValue(), rpcInvocation, serviceDeployer);
} catch (Exception exception) {
logger.error("", exception.getMessage(), "", "dubbo rest protocol execute ResponseIntercepts error", exception);
throw exception;
}
}
try {
// invoke the intercept chain before Result write to response
executeResponseIntercepts(url, request, nettyHttpResponse, result.getValue(), rpcInvocation, serviceDeployer);
} catch (Exception exception) {
logger.error("", exception.getMessage(), "", "dubbo rest protocol execute ResponseIntercepts error", exception);
throw exception;
}
}

View File

@ -85,8 +85,6 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
// first request filter
executeFilters(url, requestFacade, nettyHttpResponse, serviceDeployer, restRequestFilters);
// second response filter
executeFilters(url, requestFacade, nettyHttpResponse, serviceDeployer, restResponseFilters);
} catch (PathNoFoundException pathNoFoundException) {
logger.error("", pathNoFoundException.getMessage(), "", "dubbo rest protocol provider path no found ,raw request is :" + nettyHttpRequest, pathNoFoundException);
nettyHttpResponse.sendError(404, pathNoFoundException.getMessage());
@ -102,6 +100,14 @@ public class NettyHttpHandler implements HttpHandler<NettyRequestFacade, NettyHt
+ " , stacktrace is: " + ServiceInvokeRestFilter.stackTraceToString(throwable));
}
// second response filter
try {
executeFilters(url, requestFacade, nettyHttpResponse, serviceDeployer, restResponseFilters);
} catch (Throwable throwable) {
logger.error("", throwable.getMessage(), "", "dubbo rest protocol provider error ,and raw request is " + nettyHttpRequest, throwable);
nettyHttpResponse.sendError(500, "dubbo rest invoke Internal error, message is " + throwable.getMessage() + " ,and exception type is : " + throwable.getClass()
+ " , stacktrace is: " + ServiceInvokeRestFilter.stackTraceToString(throwable));
}
}