Skip to content
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

added error handling #98

Merged
merged 10 commits into from
Aug 20, 2024
Merged

added error handling #98

merged 10 commits into from
Aug 20, 2024

Conversation

ajaypj
Copy link
Collaborator

@ajaypj ajaypj commented Aug 16, 2024

No description provided.

// } finally {
// detachContext(contextWithHeaders, previous); // detach headers from gRPC context
// }
// }
Copy link
Collaborator Author

@ajaypj ajaypj Aug 16, 2024

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()));
Copy link
Collaborator Author

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()));
Copy link
Collaborator Author

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);
Copy link
Member

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);
Copy link
Member

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.

Comment on lines 66 to 70

/**
* Method for performing ending functions for a filter.
*/
public void doEndFilter() {}
Copy link
Member

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.

Copy link
Collaborator Author

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));
Copy link
Member

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

@@ -57,7 +58,7 @@ public class AccessLogGrpcFilter<R extends GeneratedMessageV3, S extends Generat
private static final Logger logger = Logging.loggerWithName("ACCESS-LOG");

public AccessLogGrpcFilter() {

accessLogContextBuilder.requestTime(System.currentTimeMillis());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init accessLogContextBuilder here and set requestTime

Comment on lines +43 to +46
implementation ('ru.vyarus:guice-validator:1.2.0') {
exclude group: 'com.google.inject', module: 'guice'
}
implementation 'com.google.inject:guice:5.1.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these required?

@kingster kingster merged commit ae3e091 into master Aug 20, 2024
3 checks passed
@kingster kingster deleted the error-handle branch August 20, 2024 11:32
kingster pushed a commit that referenced this pull request Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants