當前位置: 首頁>>代碼示例>>Java>>正文


Java MatrixErrorInfo類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:24,代碼來源:AMatrixHttpClient.java

示例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);
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:19,代碼來源:AMatrixHttpClient.java

示例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);
    }
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:33,代碼來源:AMatrixHttpClient.java

示例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);
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:11,代碼來源:AMatrixHttpClient.java

示例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)
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:8,代碼來源:AMatrixHttpClient.java

示例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());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:9,代碼來源:ApplicationServiceController.java

示例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());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:7,代碼來源:ApplicationServiceController.java

示例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);
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:9,代碼來源:ApplicationServiceController.java

示例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;
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:7,代碼來源:AMatrixHttpClient.java

示例10: MatrixClientRequestException

import io.kamax.matrix.MatrixErrorInfo; //導入依賴的package包/類
public MatrixClientRequestException(MatrixErrorInfo errorInfo, String message) {
    super(message);

    this.errorInfo = errorInfo;
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:6,代碼來源:MatrixClientRequestException.java

示例11: getError

import io.kamax.matrix.MatrixErrorInfo; //導入依賴的package包/類
public Optional<MatrixErrorInfo> getError() {
    return Optional.ofNullable(errorInfo);
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:4,代碼來源:MatrixClientRequestException.java

示例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());
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:6,代碼來源:MatrixHttpTest.java

示例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());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:7,代碼來源:ApplicationServiceController.java

示例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());
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:7,代碼來源:ApplicationServiceController.java

示例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)
}
 
開發者ID:kamax-io,項目名稱:matrix-java-sdk,代碼行數:15,代碼來源:AMatrixHttpClient.java


注:本文中的io.kamax.matrix.MatrixErrorInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。