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

Exception handler test coverage added #128

Merged
Changes from 2 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 @@ -12,10 +12,14 @@
*/
package com.netflix.conductor.rest.controllers;

import java.nio.channels.ClosedChannelException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.catalina.connector.ClientAbortException;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
Expand Down Expand Up @@ -53,16 +57,37 @@ public class ApplicationExceptionMapper {
EXCEPTION_STATUS_MAP.put(NoResourceFoundException.class, HttpStatus.NOT_FOUND);
}

@ExceptionHandler(ClientAbortException.class)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted my prev change - I believe we should rather ignore it from alerts than changing the error logs here or something.
Added test coverage for the existing exception handler.

@ExceptionHandler(ClosedChannelException.class)
@Order(ValidationExceptionMapper.ORDER + 1)
public void handleNestedClientAbortedInClosedChannelException(
HttpServletRequest request, ClosedChannelException closedChannelException) {
final List<Throwable> exceptionChain =
ExceptionUtils.getThrowableList(closedChannelException);
final Optional<Throwable> clientAbortedException =
exceptionChain.stream()
.filter(
t ->
ClientAbortException.class
.getName()
.equals(t.getClass().getName()))
.findAny();
if (clientAbortedException.isPresent()) {
handleClientAborted(request, (ClientAbortException) clientAbortedException.get());
return;
}
handleAll(request, closedChannelException);
}

@ExceptionHandler(ClientAbortException.class)
@Order(ValidationExceptionMapper.ORDER + 2)
public void handleClientAborted(
HttpServletRequest request, ClientAbortException clientAbortException) {
logException(
request, clientAbortException); // socket closed, cannot return any error response
}

@ExceptionHandler(Throwable.class)
@Order(ValidationExceptionMapper.ORDER + 2)
@Order(ValidationExceptionMapper.ORDER + 3)
public ResponseEntity<ErrorResponse> handleAll(HttpServletRequest request, Throwable th) {
logException(request, th);

Expand Down
Loading