Project

General

Profile

« Previous | Next » 

Revision 60105

[Trunk | Admin Tools Library]:
1. GenericPortalController.java: Added Generic portal controller for handling all portals without type limitation.
2. SimpleErrorController.java: Added /error request mapping, to format all error that are not explicitly handled.
3. AdminToolsLibraryExceptionsHandler.java: Added methods
"notFoundException()" (ChangeSetPersister.NotFoundException),
"forbiddenException()" (ForbiddenException),
"duplicateKeyException()" (DuplicateKeyException).
4. ForbiddenException.java: [NEW] Added class ForbiddenException extends RuntimeException.
5. ExceptionResponse.java: Added field HttpStatus status.
6. SingleValueWrapperResponse.java: [Moved from Admin Tools Service to Admin Tools Library]
Generic class SingleValueWrapperResponse created, with field "value" of type defined when instance is created (used for returning single value from API methods).

View differences:

AdminToolsLibraryExceptionsHandler.java
2 2

  
3 3
import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse;
4 4
import org.apache.log4j.Logger;
5
import org.springframework.dao.DuplicateKeyException;
6
import org.springframework.data.crossstore.ChangeSetPersister;
5 7
import org.springframework.http.HttpStatus;
6 8
import org.springframework.http.ResponseEntity;
7 9
import org.springframework.web.bind.MissingServletRequestParameterException;
......
62 64
        log.debug("invalidReCaptchaException exception");
63 65
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
64 66
    }
67

  
68

  
69
    @ExceptionHandler(ChangeSetPersister.NotFoundException.class)
70
    public ResponseEntity<ExceptionResponse> notFoundException(Exception ex) {
71
        ExceptionResponse response = new ExceptionResponse();
72
        response.setErrorCode("Not found Exception");
73
        response.setErrorMessage("Not found Exception");
74
        response.setErrors(ex.getMessage());
75
        response.setStatus(HttpStatus.NOT_FOUND);
76
        log.error("notFoundException exception : "+ ex.getMessage());
77
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
78
    }
79

  
80
    @ExceptionHandler(ForbiddenException.class)
81
    public ResponseEntity<ExceptionResponse> forbiddenException(Exception ex) {
82
        ExceptionResponse response = new ExceptionResponse();
83
        response.setErrorCode("Forbidden Exception");
84
        response.setErrorMessage("Forbidden Exception");
85
        response.setErrors(ex.getMessage());
86
        response.setStatus(HttpStatus.FORBIDDEN);
87
        log.error("forbiddenException exception : "+ ex.getMessage());
88
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.FORBIDDEN);
89
    }
90

  
91
    @ExceptionHandler(DuplicateKeyException.class)
92
    public ResponseEntity<ExceptionResponse> duplicateKeyException(Exception ex) {
93
        ExceptionResponse response = new ExceptionResponse();
94
        response.setErrorCode("DuplicateKey Exception");
95
        response.setErrorMessage("DuplicateKey Exception");
96
        response.setErrors(ex.getMessage());
97
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
98
        log.error("duplicateKeyException exception : "+ ex.getMessage());
99
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.INTERNAL_SERVER_ERROR);
100
    }
65 101
}

Also available in: Unified diff