当前位置: 首页>>代码示例>>Java>>正文


Java ResponseStatus.reason方法代码示例

本文整理汇总了Java中org.springframework.web.bind.annotation.ResponseStatus.reason方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseStatus.reason方法的具体用法?Java ResponseStatus.reason怎么用?Java ResponseStatus.reason使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.bind.annotation.ResponseStatus的用法示例。


在下文中一共展示了ResponseStatus.reason方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processRuntimeException

import org.springframework.web.bind.annotation.ResponseStatus; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception {
    BodyBuilder builder;
    ErrorDTO errorDTO;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason());
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
    }
    log.error("Exception in rest call", ex);
    errorDTO.add("error", "error", ex.getMessage());
    return builder.body(errorDTO);
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:17,代码来源:ExceptionTranslator.java

示例2: processRuntimeException

import org.springframework.web.bind.annotation.ResponseStatus; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) {
    log.debug("Processing runtime exception", ex);
    BodyBuilder builder;
    ErrorVM errorVM;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason());
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
    }
    return builder.body(errorVM);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:16,代码来源:ExceptionTranslator.java

示例3: defaultErrorHandler

import org.springframework.web.bind.annotation.ResponseStatus; //导入方法依赖的package包/类
@ExceptionHandler(Exception.class)
public ResponseEntity<Map<String,Object>> defaultErrorHandler(Exception e) throws Exception {
    if (e instanceof ServletException) {
        // ServletException will be handled by Spring
        throw e;
    }

    if (e instanceof AccessDeniedException) {
        // will be handled by Spring
        throw e;
    }

    final HttpStatus status;
    final String statusMessage;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        status = ObjectUtils.firstNonNull(responseStatus.code(), responseStatus.value());
        statusMessage = responseStatus.reason();
    } else {
        status = HttpStatus.INTERNAL_SERVER_ERROR;
        statusMessage = null;
    }
    final ResponseEntityBuilder reb = ResponseEntities
            .build(status)
            .message(ObjectUtils.firstNonNull(e.getMessage(),statusMessage));

    //DataExceptions can provide structured information about the error that
    //will serialized under the "data" field in the response 
    if(e instanceof DataException<?>){
        Object data = ((DataException<?>)e).getData();
        if(data != null){ //data may be null
            reb.data(data);
        }
    }

    if(writeTrace){
        reb.trace(ExceptionUtils.getStackTrace(e));
    } else {
        log.trace("trace omitted (webservice.errorhandler.writetrace=false)");
    }
    log.warn("ErrorResponse (status: {}, {}: {})", status, e.getClass().getSimpleName(), e.getMessage());
    log.debug("STACKTRACE:", e);
    return reb.build();
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:45,代码来源:GlobalDefaultExceptionHandler.java


注:本文中的org.springframework.web.bind.annotation.ResponseStatus.reason方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。