diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/errors/SpringExceptionMapper.java b/notification-core/src/main/java/org/opengroup/osdu/notification/errors/SpringExceptionMapper.java index a22bc99585a4d8026bd99669f3f18024accc9553..81b31a786d63a2411990ba00f950796ab3a521a1 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/errors/SpringExceptionMapper.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/errors/SpringExceptionMapper.java @@ -18,6 +18,8 @@ package org.opengroup.osdu.notification.errors; import com.fasterxml.jackson.core.JsonProcessingException; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; @@ -32,6 +34,7 @@ import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import org.opengroup.osdu.core.common.model.http.AppException; import javax.validation.ValidationException; +import java.io.IOException; import java.nio.file.AccessDeniedException; import java.util.List; import java.util.stream.Collectors; @@ -78,6 +81,17 @@ public class SpringExceptionMapper extends ResponseEntityExceptionHandler { "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) { if(e.getOriginalException()!= null) { this.log.error(e.getOriginalException().getMessage(), e.getOriginalException());