-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalErrorHandler.java
More file actions
28 lines (23 loc) · 1.16 KB
/
GlobalErrorHandler.java
File metadata and controls
28 lines (23 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.martincastroalvarez.london;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
@ControllerAdvice
public class GlobalErrorHandler {
// --------------------------------------------------------------------
// Global exception handler responsbile for translating Java errors
// into JSON messages that can be returned by the API controllers.
// --------------------------------------------------------------------
//
private Logger logger = LoggerFactory.getLogger(PersonController.class);
@ExceptionHandler(Exception.class)
public ResponseEntity<?> globleExcpetionHandler(Exception ex, WebRequest request) {
logger.error("Error | Handler: " + ex + " " + request);
ErrorResponse response = new ErrorResponse(ex.getClass().getName(), ex.getMessage());
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}