Skip to content
Snippets Groups Projects
Commit 1e68c930 authored by Sanjeev-SLB's avatar Sanjeev-SLB
Browse files

Broken pipe IOException handler

parent a7d0430d
No related branches found
No related tags found
1 merge request!125Broken pipe IOException handler
Pipeline #70112 failed
...@@ -18,6 +18,8 @@ package org.opengroup.osdu.notification.errors; ...@@ -18,6 +18,8 @@ package org.opengroup.osdu.notification.errors;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
...@@ -32,6 +34,7 @@ import org.springframework.web.context.request.WebRequest; ...@@ -32,6 +34,7 @@ import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.AppException;
import javax.validation.ValidationException; import javax.validation.ValidationException;
import java.io.IOException;
import java.nio.file.AccessDeniedException; import java.nio.file.AccessDeniedException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -78,6 +81,17 @@ public class SpringExceptionMapper extends ResponseEntityExceptionHandler { ...@@ -78,6 +81,17 @@ public class SpringExceptionMapper extends ResponseEntityExceptionHandler {
"An unknown error has occurred.", e)); "An unknown error has occurred.", e));
} }
@ExceptionHandler(IOException.class)
public ResponseEntity<Object> handleIOException(IOException e) {
if (StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "Broken pipe")) {
this.log.warning("Client closed the connection while request still being processed");
return null;
} else {
return this.getErrorResponse(
new AppException(HttpStatus.SERVICE_UNAVAILABLE.value(), "Unknown error", e.getMessage(), e));
}
}
private ResponseEntity<Object> getErrorResponse(AppException e) { private ResponseEntity<Object> getErrorResponse(AppException e) {
if(e.getOriginalException()!= null) { if(e.getOriginalException()!= null) {
this.log.error(e.getOriginalException().getMessage(), e.getOriginalException()); this.log.error(e.getOriginalException().getMessage(), e.getOriginalException());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment