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


Java HttpStatusCodeException.getMessage方法代码示例

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


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

示例1: getHttpErrorMessage

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
 * 
 * @param error
 * @return Error message containing description of the error. If no
 * description is found, it will return the exception error or HTTP status
 * text message, if present. May return null if no message can be resolved.
 */
protected static String getHttpErrorMessage(HttpStatusCodeException error) {
	String message = null;
	if (error instanceof CloudFoundryException) {
		message = ((CloudFoundryException) error).getDescription();
	}

	if (message == null) {
		message = error.getMessage();
		if (message == null) {
			message = error.getStatusText();
			if (message == null) {
				message = error.getResponseBodyAsString();
			}
		}
	}
	return message;
}
 
开发者ID:eclipse,项目名称:cft,代码行数:25,代码来源:CloudErrorUtil.java

示例2: retrieveErrorMessage

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
protected String retrieveErrorMessage(Throwable e) {
    if (e instanceof HttpStatusCodeException) {
        HttpStatusCodeException ex = (HttpStatusCodeException) e;
        return ex.getMessage() + ": " + ex.getResponseBodyAsString();
    }
    return e.getMessage();
}
 
开发者ID:mkopylec,项目名称:charon-spring-boot-starter,代码行数:8,代码来源:LoggingListener.java

示例3: run

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
/**
 * This delagates actual execution to {@link #runWithUrl(String)} and handles any
 * Spring Rest exceptions, wrapping them as necessary. Default behavior is to throw
 * a {@link RetryableApiCommandException} for 5xx errors and timeouts, and {@link
 * NonRetryableApiCommandException} for all others. If you need different behavior
 * your best bet is to write your own {@link RemoteServiceCallback} and/or use
 * the various flavors of {@link org.springframework.web.client.RestTemplate} that
 * take let you provide {@link ResponseErrorHandler}.
 * @param url The URL of the remote service.
 * @return Result of the remote call, or potentially throws an exception if an
 * error occurs calling the remote service.
 */
@Override
public T run(String url)
{
   T response = null;

   try
   {
      LOG.debug("Running command {} with URL {}", getContext().getCommandName(), url);
      response = runWithUrl(url);
   }
   catch (HttpStatusCodeException hsce)
   {
      if (hsce.getStatusCode()         == HttpStatus.REQUEST_TIMEOUT ||
          hsce.getStatusCode().value() >= 500)
      {
         throw new RetryableApiCommandException("Remote server error: " + hsce.getMessage(), hsce);
      }
      else
      {
         throw new NonRetryableApiCommandException("Local client error: " + hsce.getMessage(), hsce);
      }
   }
   catch(HttpMessageConversionException e)
   {
      throw new NonRetryableApiCommandException("Invalid response from server: " + e.getMessage(), e);
   }

   LOG.debug("Returning response {}", response);
   return response;
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:43,代码来源:SpringInstanceCallback.java

示例4: handleHttpStatusCodeException

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
@ExceptionHandler(HttpStatusCodeException.class)
public void handleHttpStatusCodeException(
        HttpStatusCodeException e,
        HttpServletResponse response) throws IOException {
    String message = extractErrorFromJSON(e.getResponseBodyAsString());
    message = StringUtils.isNotBlank(message) ? message : e.getMessage();
    logAndSendErrorResponse(response, e.getStatusCode(), message, e);
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:9,代码来源:WebErrorHandlers.java

示例5: getMessage

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
private String getMessage(String task, String url, HttpStatusCodeException e) {
    String message = e.getMessage();
    String jsonResponse = e.getResponseBodyAsString();
    if (StringUtils.hasText(jsonResponse)) {
        JsonNode json = POMUtils.parseJSONtoNode(jsonResponse);
        JsonNode firstError = json.path("error").path("errors").path(0);
        message += "; " + firstError.path("message").asText();
    }
    return "JDS error during " + task + " at \"" + url + "\": " + message;
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:11,代码来源:DefaultJdsExceptionTranslator.java

示例6: handleConstraintViolation

import org.springframework.web.client.HttpStatusCodeException; //导入方法依赖的package包/类
@ExceptionHandler({ HttpServerErrorException.class, HttpClientErrorException.class})
public ResponseEntity<ApiError> handleConstraintViolation(WebRequest request, HttpStatusCodeException ex) {
    ApiError apiError = new ApiError(ex.getStatusCode(), ex.getMessage());
    return new ResponseEntity<>(apiError, ex.getStatusCode());
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:6,代码来源:ApiExceptionHandler.java


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