Example usage for io.netty.handler.codec.http HttpStatusClass CLIENT_ERROR

List of usage examples for io.netty.handler.codec.http HttpStatusClass CLIENT_ERROR

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpStatusClass CLIENT_ERROR.

Prototype

HttpStatusClass CLIENT_ERROR

To view the source code for io.netty.handler.codec.http HttpStatusClass CLIENT_ERROR.

Click Source Link

Document

The client error class (4xx)

Usage

From source file:com.ibasco.agql.core.AbstractWebApiInterface.java

License:Open Source License

/**
 * The default error handler. Override this if needed.
 *
 * @param response An instance of {@link AbstractWebApiResponse} or <code>null</code> if an exception was thrown.
 * @param error    A {@link Throwable} instance or <code>null</code> if no error has occured.
 *
 * @throws WebException thrown if a server/client error occurs
 *//*from w w w  . j a v  a 2s  .  c  om*/
protected void interceptResponse(Res response, Throwable error) {
    if (error != null)
        throw new WebException(error);
    log.debug("Handling response for {}, with status code = {}", response.getMessage().getUri(),
            response.getMessage().getStatusCode());
    if (response.getStatus() == HttpStatusClass.SERVER_ERROR
            || response.getStatus() == HttpStatusClass.CLIENT_ERROR) {
        switch (response.getMessage().getStatusCode()) {
        case 400:
            throw new BadRequestException("Incorrect parameters provided for request");
        case 403:
            throw new AccessDeniedException(
                    "Access denied, either because of missing/incorrect credentials or used API token does not grant access to the requested resource.");
        case 404:
            throw new ResourceNotFoundException("Resource was not found.");
        case 429:
            throw new TooManyRequestsException(
                    "Request was throttled, because amount of requests was above the threshold defined for the used API token.");
        case 500:
            throw new UnknownWebException("An internal error occured in server");
        case 503:
            throw new ServiceUnavailableException(
                    "Service is temprorarily unavailable. Possible maintenance on-going.");
        default:
            throw new WebException("Unknown error occured on request send");
        }
    }
}

From source file:com.ibasco.agql.protocols.supercell.coc.webapi.CocWebApiInterface.java

License:Open Source License

/**
 * Handle Error Events//w ww  .j  a va2 s.  c o  m
 *
 * @param response
 * @param error
 */
@Override
protected void interceptResponse(CocWebApiResponse response, Throwable error) {
    if (error != null)
        throw new CocWebApiException(error);
    if (response.getStatus() == HttpStatusClass.CLIENT_ERROR) {
        if (response.getProcessedContent() != null) {
            CocErrorResponse err = builder().fromJson(response.getProcessedContent(), CocErrorResponse.class);
            log.error("[ERROR FROM {}]: Reason: {}, Message: {}", response.sender(), err.getReason(),
                    err.getMessage());
        }
        switch (response.getMessage().getStatusCode()) {
        case 400:
            throw new CocIncorrectParametersException("Incorrect parameters provided for request");
        default:
            break;
        }
        //Let the base class handle the rest
        super.interceptResponse(response, error);
    }
}