Spring Framework ResponseEntityExceptionHandler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ResponseEntityExceptionHandler class.

This code example shows how to use the following methods:
 * 自定义ExceptionHandler,专门处理Hystrix异常. 
 *  
 * @author calvin 
 */ 
@ControllerAdvice 
public class HystrixExceptionHandler extends ResponseEntityExceptionHandler {
 
	/** 
	 * 处理Hystrix Runtime异常, 分为两类: 
	 * 一类是Command内部抛出异常(返回500). 
	 * 一类是Hystrix已进入保护状态(返回503). 
	 */ 
	@ExceptionHandler(value = { HystrixRuntimeException.class }) 
	public final ResponseEntity<?> handleException(HystrixRuntimeException e, WebRequest request) {
		HttpStatus status = HttpStatus.SERVICE_UNAVAILABLE;
		String message = e.getMessage();
 
		FailureType type = e.getFailureType();
 
		// 对命令抛出的异常进行特殊处理 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
/** 
 * Spring MVC exception handler user to map JPA related exception to HTTP error codes. 
 * Spring MVC is an optional dependency, it will be used only if already imported by your application. 
 */ 
@ControllerAdvice 
public class JpaHandlerExceptionHandler extends ResponseEntityExceptionHandler {
 
    @ExceptionHandler(value={ 
            ObjectNotFoundException.class,
            EntityNotFoundException.class, 
            EntityExistsException.class, 
            DataIntegrityViolationException.class 
    }) 
    public ResponseEntity<Object> handleCustomException(Exception ex, WebRequest request) {
 
        HttpHeaders headers = new HttpHeaders();
        HttpStatus status;
 
        if (ex instanceof ObjectNotFoundException) {
            status = HttpStatus.NOT_FOUND;
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
/** 
 * RESThub default exception handler for most common exceptions. 
 */ 
@ControllerAdvice 
public class ResthubExceptionHandler extends ResponseEntityExceptionHandler {
 
    @ExceptionHandler(value={ 
            IllegalArgumentException.class,
            ValidationException.class,
            NotFoundException.class, 
            NotImplementedException.class 
    }) 
    public ResponseEntity<Object> handleCustomException(Exception ex, WebRequest request) {
 
        HttpHeaders headers = new HttpHeaders();
        HttpStatus status;
 
        if (ex instanceof IllegalArgumentException) {
            status = HttpStatus.BAD_REQUEST;
4
CodeRank
Experience pair programming with AI  Get Codota for Java