Skip to content

Commit

Permalink
Let spring handle its own errors instead of returning 500 for them (e…
Browse files Browse the repository at this point in the history
….g. NoResourceFoundException should return 404)
  • Loading branch information
tdrwenski committed Aug 20, 2024
1 parent b2b2ebf commit 445f34c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tds/src/main/java/thredds/server/TdsErrorHandling.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down Expand Up @@ -174,7 +175,8 @@ public ResponseEntity<String> handle(Throwable ex) throws Throwable {
// at the start of this post.
// AnnotationUtils is a Spring Framework utility class.
// see https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
if (AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class) != null)
// or if it is a spring ErrorResponse let the spring handlers deal with it
if (AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class) != null || ex instanceof ErrorResponse)
throw ex;

logger.error("uncaught exception", ex);
Expand Down

0 comments on commit 445f34c

Please sign in to comment.