本文整理匯總了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);
}
示例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);
}
示例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();
}