當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。