Skip to content

Commit

Permalink
Merge pull request #136 from europeana/EA-3781_add_logging_for_all_ex…
Browse files Browse the repository at this point in the history
…ceptions

do log all exceptions
  • Loading branch information
gsergiu authored Apr 23, 2024
2 parents 58f0b98 + 63d86a0 commit d1fb2d3
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected boolean stackTraceEnabled(){
@ExceptionHandler(HttpException.class)
public ResponseEntity<EuropeanaApiErrorResponse> handleCommonHttpException(
HttpException e, HttpServletRequest httpRequest) {
LOG.error("Error response: ", e);
EuropeanaApiErrorResponse response =
new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(e.getStatus().value())
Expand Down Expand Up @@ -163,7 +164,7 @@ protected String buildResponseMessage(Exception e, String i18nKey, String[] i18n
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleOtherExceptionTypes(Exception e, HttpServletRequest httpRequest) {
LOG.error("Error: ", e);
LOG.error("Unexpected Internal Server Error:", e);
HttpStatus responseStatus = HttpStatus.INTERNAL_SERVER_ERROR;
EuropeanaApiErrorResponse response = new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(responseStatus.value())
Expand All @@ -183,6 +184,7 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleOtherExceptionTypes(Excep
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleHttpMethodNotSupportedException(HttpRequestMethodNotSupportedException e, HttpServletRequest httpRequest) {
LOG.error("Method not allowed Error (405):", e);
HttpStatus responseStatus = HttpStatus.METHOD_NOT_ALLOWED;
EuropeanaApiErrorResponse response = new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(responseStatus.value())
Expand Down Expand Up @@ -210,6 +212,7 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleHttpMethodNotSupportedExc
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleInputValidationError(ConstraintViolationException e, HttpServletRequest httpRequest) {
LOG.error("Bad Request Error (400):", e);
HttpStatus responseStatus = HttpStatus.BAD_REQUEST;
EuropeanaApiErrorResponse response = new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(responseStatus.value())
Expand All @@ -228,6 +231,7 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleInputValidationError(Cons
*/
@ExceptionHandler
public ResponseEntity<EuropeanaApiErrorResponse> handleInputValidationError(MissingServletRequestParameterException e, HttpServletRequest httpRequest) {
LOG.error("Bad Request Error (400):", e);
HttpStatus responseStatus = HttpStatus.BAD_REQUEST;
EuropeanaApiErrorResponse response = (new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled()))
.setStatus(responseStatus.value())
Expand All @@ -248,7 +252,7 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleInputValidationError(Miss
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public ResponseEntity<EuropeanaApiErrorResponse> handleMediaTypeNotAcceptableException(
HttpMediaTypeNotAcceptableException e, HttpServletRequest httpRequest) {

LOG.error("Media Format not Acceptable Error (406):", e);
HttpStatus responseStatus = HttpStatus.NOT_ACCEPTABLE;
EuropeanaApiErrorResponse response = new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(responseStatus.value())
Expand All @@ -271,6 +275,7 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleMediaTypeNotAcceptableExc
@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<EuropeanaApiErrorResponse> handleNoHandlerFoundException(
NoHandlerFoundException e, HttpServletRequest httpRequest) {
LOG.error("Not found (404):", e);
EuropeanaApiErrorResponse response =
new EuropeanaApiErrorResponse.Builder(httpRequest, e, stackTraceEnabled())
.setStatus(HttpStatus.NOT_FOUND.value())
Expand All @@ -287,7 +292,8 @@ public ResponseEntity<EuropeanaApiErrorResponse> handleNoHandlerFoundException(
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<EuropeanaApiErrorResponse> handleMethodArgNotValidException(MethodArgumentNotValidException e, HttpServletRequest httpRequest) {
BindingResult result = e.getBindingResult();
LOG.error("Bad Request Error (400):", e);
BindingResult result = e.getBindingResult();
String error ="";
List<FieldError> fieldErrors = result.getFieldErrors();
if(!fieldErrors.isEmpty()) {
Expand Down

0 comments on commit d1fb2d3

Please sign in to comment.