Project

General

Profile

« Previous | Next » 

Revision 59470

[Trunk | Admin Tools]: Merging branch 'use-UoaAdminToolsLibrary' into trunk for revisions 58365:59468

View differences:

ExceptionsHandler.java
1 1
package eu.dnetlib.uoaadmintools.handlers;
2 2

  
3
import eu.dnetlib.uoaadmintools.responses.ExceptionResponse;
3
import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse;
4 4

  
5
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
5 6
import org.apache.log4j.Logger;
6 7
import org.springframework.http.HttpStatus;
7 8
import org.springframework.http.ResponseEntity;
......
9 10
import org.springframework.web.bind.annotation.ControllerAdvice;
10 11
import org.springframework.web.bind.annotation.ExceptionHandler;
11 12

  
12
import java.util.Date;
13

  
14 13
@ControllerAdvice
15 14
public class ExceptionsHandler {
16 15
    private final Logger log = Logger.getLogger(this.getClass());
17 16

  
18
    @ExceptionHandler(MissingServletRequestParameterException.class)
19
    public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
20
        ExceptionResponse response = new ExceptionResponse();
21
        response.setErrorCode("Validation Error");
22
        response.setErrorMessage("Invalid inputs.");
23
        response.setErrors(ex.getMessage());
24
        log.debug("invalidInput exception");
25

  
26
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
27
    }
28
    @ExceptionHandler(ContentNotFoundException.class)
29
    public ResponseEntity<ErrorDetails> contentNotFound(Exception ex) {
30
        ExceptionResponse response = new ExceptionResponse();
31
        response.setErrorCode("No content found");
32
        response.setErrorMessage(ex.getMessage());
33
        response.setErrors(ex.getMessage());
34
        ErrorDetails errorDetails = new ErrorDetails(new Date(),ex.getMessage(),ex.getMessage());
35
        log.debug("contentNotFound exception" + response.getErrorCode()+ " "+response.getErrorMessage());
36

  
37
        return new ResponseEntity<ErrorDetails>(errorDetails, HttpStatus.NOT_FOUND);
38
    }
39
    @ExceptionHandler(NullPointerException.class)
40
    public ResponseEntity<ExceptionResponse> nullPointerException(Exception ex) {
41
        ExceptionResponse response = new ExceptionResponse();
42
        response.setErrorCode("Null pointer Exception");
43
        response.setErrorMessage("Null pointer Exception");
44
        response.setErrors(ex.getMessage());
45
        log.debug("nullPointerException exception");
46
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
47
    }
48

  
49
    @ExceptionHandler(InvalidReCaptchaException.class)
50
    public ResponseEntity<ExceptionResponse> invalidReCaptchaException(Exception ex) {
51
        ExceptionResponse response = new ExceptionResponse();
52
        response.setErrorCode("Invalid ReCaptcha Exception");
53
        response.setErrorMessage("Invalid ReCaptcha Exception");
54
        response.setErrors(ex.getMessage());
55
        log.debug("invalidReCaptchaException exception");
56
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
57
    }
17
//    @ExceptionHandler(MissingServletRequestParameterException.class)
18
//    public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
19
//        ExceptionResponse response = new ExceptionResponse();
20
//        response.setErrorCode("Validation Error");
21
//        response.setErrorMessage("Invalid inputs.");
22
//        response.setErrors(ex.getMessage());
23
//        log.debug("invalidInput exception");
24
//
25
//        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
26
//    }
27
//    @ExceptionHandler(ContentNotFoundException2.class)
28
//    public ResponseEntity<ExceptionResponse> contentNotFound(Exception ex) {
29
//        ExceptionResponse response = new ExceptionResponse();
30
//        response.setErrorCode("No content found");
31
//        response.setErrorMessage(ex.getMessage());
32
//        response.setErrors(ex.getMessage());
33
//        log.debug("contentNotFound exception" + response.getErrorCode()+ " "+response.getErrorMessage());
34
//        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
35
//    }
36
//    @ExceptionHandler(NullPointerException.class)
37
//    public ResponseEntity<ExceptionResponse> nullPointerException(Exception ex) {
38
//        ExceptionResponse response = new ExceptionResponse();
39
//        response.setErrorCode("Null pointer Exception");
40
//        response.setErrorMessage("Null pointer Exception");
41
//        response.setErrors(ex.getMessage());
42
//        log.debug("nullPointerException exception");
43
//        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
44
//    }
45
//    @ExceptionHandler(InvalidReCaptchaException.class)
46
//    public ResponseEntity<ExceptionResponse> invalidReCaptchaException(Exception ex) {
47
//        ExceptionResponse response = new ExceptionResponse();
48
//        response.setErrorCode("Invalid ReCaptcha Exception");
49
//        response.setErrorMessage("Invalid ReCaptcha Exception");
50
//        response.setErrors(ex.getMessage());
51
//        log.debug("invalidReCaptchaException exception");
52
//        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
53
//    }
58 54
}

Also available in: Unified diff