use of com.sbsk.model.ApiError 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);
}
use of com.sbsk.model.ApiError 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);
}
use of com.sbsk.model.ApiError 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;
}
Aggregations