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

Fix #1611: 404 error is propagated as 500 #1612

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -40,6 +40,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.resource.NoResourceFoundException;

/**
* Controller advice responsible for default exception resolving.
Expand Down Expand Up @@ -862,4 +863,17 @@ public DefaultExceptionResolver(Audit audit) {
return new ErrorResponse(error);
}

/**
* Exception handler for no resource found.
*
* @param e Exception.
* @return Response with error details.
*/
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public @ResponseBody ErrorResponse handleNoResourceFoundException(final NoResourceFoundException e) {
logger.warn("Error occurred when calling an API: {}", e.getMessage());
logger.debug("Exception detail: ", e);
return new ErrorResponse("ERROR_NOT_FOUND", "Resource not found.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.resource.NoResourceFoundException;

/**
* Controller advice responsible for default exception resolving.
Expand Down Expand Up @@ -141,4 +142,17 @@ public DefaultExceptionResolver(Audit audit) {
return new ErrorResponse(new TppAppError("tpp.app.unableToCreate", t.getErrors()));
}

}
/**
* Exception handler for no resource found.
*
* @param e Exception.
* @return Response with error details.
*/
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public @ResponseBody ErrorResponse handleNoResourceFoundException(final NoResourceFoundException e) {
logger.warn("Error occurred when calling an API: {}", e.getMessage());
logger.debug("Exception detail: ", e);
return new ErrorResponse("ERROR_NOT_FOUND", "Resource not found.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.resource.NoResourceFoundException;

/**
* Controller advice responsible for default exception resolving.
Expand Down Expand Up @@ -134,4 +135,17 @@ public String handleUnauthorizedException(InsufficientAuthenticationException ex
return new ErrorResponse(error);
}

/**
* Exception handler for no resource found.
*
* @param e Exception.
* @return Response with error details.
*/
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public @ResponseBody ErrorResponse handleNoResourceFoundException(final NoResourceFoundException e) {
logger.warn("Error occurred when calling an API: {}", e.getMessage());
logger.debug("Exception detail: ", e);
return new ErrorResponse("ERROR_NOT_FOUND", "Resource not found.");
}
}