本文整理汇总了Java中io.kamax.matrix.MatrixErrorInfo类的典型用法代码示例。如果您正苦于以下问题:Java MatrixErrorInfo类的具体用法?Java MatrixErrorInfo怎么用?Java MatrixErrorInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MatrixErrorInfo类属于io.kamax.matrix包,在下文中一共展示了MatrixErrorInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
protected String execute(MatrixHttpRequest matrixRequest) {
log(matrixRequest.getHttpRequest());
try (CloseableHttpResponse response = client.execute(matrixRequest.getHttpRequest())) {
String body = getBody(response.getEntity());
int responseStatus = response.getStatusLine().getStatusCode();
if (responseStatus == 200) {
log.debug("Request successfully executed.");
} else if (matrixRequest.getIgnoredErrorCodes().contains(responseStatus)) {
log.debug("Error code ignored: " + responseStatus);
return "";
} else {
MatrixErrorInfo info = createErrorInfo(body, responseStatus);
body = handleError(matrixRequest, responseStatus, info);
}
return body;
} catch (IOException e) {
throw new MatrixClientRequestException(e);
}
}
示例2: handleError
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
/**
* Default handling of errors. Can be overwritten by a custom implementation in inherited classes.
*
* @param matrixRequest
* @param responseStatus
* @param info
* @return body of the response of a repeated call of the request, else this methods throws a
* MatrixClientRequestException
*/
protected String handleError(MatrixHttpRequest matrixRequest, int responseStatus, MatrixErrorInfo info) {
String message = String.format("Request failed with status code: %s", responseStatus);
if (responseStatus == 429) {
return handleRateLimited(matrixRequest, info);
}
throw new MatrixClientRequestException(info, message);
}
示例3: executeContentRequest
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
protected MatrixHttpContentResult executeContentRequest(MatrixHttpRequest matrixRequest) {
log(matrixRequest.getHttpRequest());
try (CloseableHttpResponse response = client.execute(matrixRequest.getHttpRequest())) {
HttpEntity entity = response.getEntity();
int responseStatus = response.getStatusLine().getStatusCode();
MatrixHttpContentResult result = new MatrixHttpContentResult(response);
if (responseStatus == 200) {
log.debug("Request successfully executed.");
if (entity == null) {
log.debug("No data received.");
} else if (entity.getContentType() == null) {
log.debug("No content type was given.");
}
} else if (matrixRequest.getIgnoredErrorCodes().contains(responseStatus)) {
log.debug("Error code ignored: " + responseStatus);
} else {
String body = getBody(entity);
MatrixErrorInfo info = createErrorInfo(body, responseStatus);
result = handleErrorContentRequest(matrixRequest, responseStatus, info);
}
return result;
} catch (IOException e) {
throw new MatrixClientRequestException(e);
}
}
示例4: handleErrorContentRequest
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
protected MatrixHttpContentResult handleErrorContentRequest(MatrixHttpRequest matrixRequest, int responseStatus,
MatrixErrorInfo info) {
String message = String.format("Request failed with status code: %s", responseStatus);
if (responseStatus == 429) {
return handleRateLimitedContentRequest(matrixRequest, info);
}
throw new MatrixClientRequestException(info, message);
}
示例5: handleRateLimitedContentRequest
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
protected MatrixHttpContentResult handleRateLimitedContentRequest(MatrixHttpRequest matrixRequest,
MatrixErrorInfo info) {
throw new MatrixClientRequestException(info, "Request was rate limited.");
// TODO Add default handling of rate limited call, i.e. repeated call after given time interval.
// 1. Wait for timeout
// 2. return execute(request)
}
示例6: handleBadRequest
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler({InvalidMatrixIdException.class, InvalidBodyContentException.class})
@ResponseBody
MatrixErrorInfo handleBadRequest(HttpServletRequest request, MatrixException e) {
log.error("Error when processing {} {}", request.getMethod(), request.getServletPath(), e);
return new MatrixErrorInfo(e.getErrorCode());
}
示例7: handleUnauthorized
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
@ExceptionHandler(NoHomeserverTokenException.class)
@ResponseBody
MatrixErrorInfo handleUnauthorized(MatrixException e) {
return new MatrixErrorInfo(e.getErrorCode());
}
示例8: handleGeneric
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Throwable.class)
@ResponseBody
MatrixErrorInfo handleGeneric(HttpServletRequest request, Throwable t) {
log.error("Error when processing {} {}", request.getMethod(), request.getServletPath(), t);
return new MatrixErrorInfo(t);
}
示例9: createErrorInfo
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
private MatrixErrorInfo createErrorInfo(String body, int responseStatus) {
MatrixErrorInfo info = gson.fromJson(body, MatrixErrorInfo.class);
log.debug("Request returned with an error. Status code: {}, errcode: {}, error: {}", responseStatus,
info.getErrcode(), info.getError());
return info;
}
示例10: MatrixClientRequestException
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
public MatrixClientRequestException(MatrixErrorInfo errorInfo, String message) {
super(message);
this.errorInfo = errorInfo;
}
示例11: getError
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
public Optional<MatrixErrorInfo> getError() {
return Optional.ofNullable(errorInfo);
}
示例12: checkErrorInfo
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
protected void checkErrorInfo(String errcode, String error, Optional<MatrixErrorInfo> errorOptional) {
assertTrue(errorOptional.isPresent());
assertEquals(errcode, errorOptional.get().getErrcode());
assertEquals(error, errorOptional.get().getError());
}
示例13: handleForbidden
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
@ResponseStatus(value = HttpStatus.FORBIDDEN)
@ExceptionHandler(InvalidHomeserverTokenException.class)
@ResponseBody
MatrixErrorInfo handleForbidden(MatrixException e) {
return new MatrixErrorInfo(e.getErrorCode());
}
示例14: handleNotFound
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ExceptionHandler({RoomNotFoundException.class, UserNotFoundException.class})
@ResponseBody
MatrixErrorInfo handleNotFound(MatrixException e) {
return new MatrixErrorInfo(e.getErrorCode());
}
示例15: handleRateLimited
import io.kamax.matrix.MatrixErrorInfo; //导入依赖的package包/类
/**
* Default handling of rate limited calls. Can be overwritten by a custom implementation in inherited classes.
*
* @param matrixRequest
* @param info
* @return body of the response of a repeated call of the request, else this methods throws a
* MatrixClientRequestException
*/
protected String handleRateLimited(MatrixHttpRequest matrixRequest, MatrixErrorInfo info) {
throw new MatrixClientRequestException(info, "Request was rate limited.");
// TODO Add default handling of rate limited call, i.e. repeated call after given time interval.
// 1. Wait for timeout
// 2. return execute(request)
}