-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Handling in Interceptors #98
Conversation
// } finally { | ||
// detachContext(contextWithHeaders, previous); // detach headers from gRPC context | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with close() we can get the exact Status and print it in the access logs.
Need to check how to get this with onCancel() because close() is not guaranteed to be called always according to the javadocs.
@@ -168,10 +200,10 @@ public void onMessage(Req request) { | |||
public void onCancel() { | |||
Context previous = attachContext(contextWithHeaders); // attaching headers to gRPC context | |||
try { | |||
grpcFilters.forEach(filter -> filter.doHandleException(new Exception())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any better way to get more specific exception/grpc status
} catch (RuntimeException ex) { | ||
handleException(call, ex); | ||
grpcFilters.forEach(filter -> filter.doHandleException(ex)); | ||
grpcFilters.forEach(filter -> filter.doHandleException(new Exception())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check how to set more descriptive exception containing grpc status code here, like DEADLINE_EXCEEDED
super.onComplete(); | ||
grpcFilters.forEach(Filter::doEndFilter); | ||
} catch (Exception e) { | ||
handleException(call, grpcFilters, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be calling handleException here. HandleException is for upstream. For Filter thrown error that needs to be returned without giving it back to the same filter.
grpcFilters.forEach(filter -> filter.doHandleException(new Exception())); | ||
grpcFilters.forEach(Filter::doEndFilter); | ||
} catch (Exception e) { | ||
handleException(call, grpcFilters, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we shouldn't be calling handleException here. HandleException is for upstream. For Filter thrown error that needs to be returned without giving it back to the same filter.
|
||
/** | ||
* Method for performing ending functions for a filter. | ||
*/ | ||
public void doEndFilter() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in favor of this. We already have an destroy
method. Lifecycle methods should be used only for lifecycle and not for logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not for ending lifecycle. This is for printing logs once only.
@@ -91,19 +92,23 @@ public final void doFilter(ServletRequest request, ServletResponse response, | |||
.stream().collect(Collectors.toMap(String::toLowerCase, httpServletResponse::getHeader)); | |||
filters.forEach(filter -> filter.doProcessResponseHeaders(responseHeaders)); | |||
responseHeaders.forEach(responseWrapper::setHeader); | |||
filters.forEach(filter -> filter.doProcessResponse(responseWrapper)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause filter thrown exception to be caught. We don't want that. Filter thrown error should not be caught
No description provided.