From 1e68c930230f3a07fd10d2b6090c60066407ca76 Mon Sep 17 00:00:00 2001 From: Sanjeev Pellikoduku <SPellikoduku@slb.com> Date: Tue, 5 Oct 2021 13:43:44 -0500 Subject: [PATCH] Broken pipe IOException handler --- .../notification/errors/SpringExceptionMapper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 a22bc9958..81b31a786 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()); -- GitLab