Search in sources :

Example 1 with ApiErrorResponse

use of com.sbsk.model.ApiErrorResponse in project spring-boot-starter-kit by tripsta.

the class ExceptionHandlingAdvisor method handleNoSessionIdException.

/**
 * NoSessionIdException,
 * Session Id is required
 *
 * @param e
 * @return
 */
@ExceptionHandler(NoSessionIdException.class)
public HttpEntity<ApiErrorResponse> handleNoSessionIdException(NoSessionIdException e) {
    logger.warn("Session Id is required " + e.getMessage(), e);
    ApiErrorResponse errorResponse = new ApiErrorResponse();
    errorResponse.addError(new ApiError("session id is required", ExceptionType.ADVISORY));
    return new ResponseEntity<ApiErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiErrorResponse(com.sbsk.model.ApiErrorResponse) ApiError(com.sbsk.model.ApiError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 2 with ApiErrorResponse

use of com.sbsk.model.ApiErrorResponse in project spring-boot-starter-kit by tripsta.

the class ExceptionHandlingAdvisor method handleMethodArgumentNotValidException.

@ExceptionHandler(MethodArgumentNotValidException.class)
public HttpEntity<ApiErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
    logger.warn("Invalid request " + e.getMessage(), e);
    List<ApiError> errorsList = new ArrayList<ApiError>();
    ApiErrorResponse errorResponse = new ApiErrorResponse();
    for (ObjectError error : e.getBindingResult().getAllErrors()) {
        String errorMsg = createErrorMessage(error);
        errorsList.add(new ApiError(errorMsg, ExceptionType.FIELD_VALIDATION));
    }
    errorResponse.addErrors(errorsList);
    return new ResponseEntity<ApiErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ObjectError(org.springframework.validation.ObjectError) ArrayList(java.util.ArrayList) ApiErrorResponse(com.sbsk.model.ApiErrorResponse) ApiError(com.sbsk.model.ApiError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 3 with ApiErrorResponse

use of com.sbsk.model.ApiErrorResponse in project spring-boot-starter-kit by tripsta.

the class ExceptionHandlingAdvisor method createErrorResponse.

public static ApiErrorResponse createErrorResponse(String message, ExceptionType type) {
    ApiErrorResponse errorResponse = new ApiErrorResponse();
    errorResponse.addError(new ApiError(message, type));
    return errorResponse;
}
Also used : ApiErrorResponse(com.sbsk.model.ApiErrorResponse) ApiError(com.sbsk.model.ApiError)

Aggregations

ApiError (com.sbsk.model.ApiError)3 ApiErrorResponse (com.sbsk.model.ApiErrorResponse)3 ResponseEntity (org.springframework.http.ResponseEntity)2 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)2 ArrayList (java.util.ArrayList)1 ObjectError (org.springframework.validation.ObjectError)1