Search in sources :

Example 1 with NotAllowedException

use of org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException in project pulsar by yahoo.

the class BaseResource method getApiException.

public PulsarAdminException getApiException(Throwable e) {
    if (e instanceof PulsarAdminException) {
        return (PulsarAdminException) e;
    } else if (e instanceof ServiceUnavailableException) {
        if (e.getCause() instanceof java.net.ConnectException) {
            return new ConnectException(e.getCause());
        } else {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new PulsarAdminException(e, httpError, statusCode);
        }
    } else if (e instanceof WebApplicationException) {
        // Handle 5xx exceptions
        if (e instanceof ServerErrorException) {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new ServerSideErrorException(see, httpError, httpError, statusCode);
        } else if (e instanceof ClientErrorException) {
            // Handle 4xx exceptions
            ClientErrorException cee = (ClientErrorException) e;
            int statusCode = cee.getResponse().getStatus();
            String httpError = getReasonFromServer(cee);
            switch(statusCode) {
                case 401:
                case 403:
                    return new NotAuthorizedException(cee, httpError, statusCode);
                case 404:
                    return new NotFoundException(cee, httpError, statusCode);
                case 405:
                    return new NotAllowedException(cee, httpError, statusCode);
                case 409:
                    return new ConflictException(cee, httpError, statusCode);
                case 412:
                    return new PreconditionFailedException(cee, httpError, statusCode);
                default:
                    return new PulsarAdminException(httpError, cee, httpError, statusCode);
            }
        } else {
            WebApplicationException wae = (WebApplicationException) e;
            int statusCode = wae.getResponse().getStatus();
            String httpError = getReasonFromServer(wae);
            return new PulsarAdminException(httpError, wae, httpError, statusCode);
        }
    } else {
        return new PulsarAdminException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NotAllowedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) NotAuthorizedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) ServerSideErrorException(org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ServerErrorException(javax.ws.rs.ServerErrorException) ConnectException(org.apache.pulsar.client.admin.PulsarAdminException.ConnectException)

Example 2 with NotAllowedException

use of org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException in project incubator-pulsar by apache.

the class BaseResource method getApiException.

public PulsarAdminException getApiException(Throwable e) {
    if (e instanceof PulsarAdminException) {
        return (PulsarAdminException) e;
    } else if (e instanceof ServiceUnavailableException) {
        if (e.getCause() instanceof java.net.ConnectException) {
            return new ConnectException(e.getCause());
        } else {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new PulsarAdminException(e, httpError, statusCode);
        }
    } else if (e instanceof WebApplicationException) {
        // Handle 5xx exceptions
        if (e instanceof ServerErrorException) {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new ServerSideErrorException(see, httpError, httpError, statusCode);
        } else if (e instanceof ClientErrorException) {
            // Handle 4xx exceptions
            ClientErrorException cee = (ClientErrorException) e;
            int statusCode = cee.getResponse().getStatus();
            String httpError = getReasonFromServer(cee);
            switch(statusCode) {
                case 401:
                case 403:
                    return new NotAuthorizedException(cee, httpError, statusCode);
                case 404:
                    return new NotFoundException(cee, httpError, statusCode);
                case 405:
                    return new NotAllowedException(cee, httpError, statusCode);
                case 409:
                    return new ConflictException(cee, httpError, statusCode);
                case 412:
                    return new PreconditionFailedException(cee, httpError, statusCode);
                default:
                    return new PulsarAdminException(httpError, cee, httpError, statusCode);
            }
        } else {
            WebApplicationException wae = (WebApplicationException) e;
            int statusCode = wae.getResponse().getStatus();
            String httpError = getReasonFromServer(wae);
            return new PulsarAdminException(httpError, wae, httpError, statusCode);
        }
    } else {
        return new PulsarAdminException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NotAllowedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) NotAuthorizedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) ServerSideErrorException(org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ServerErrorException(javax.ws.rs.ServerErrorException) ConnectException(org.apache.pulsar.client.admin.PulsarAdminException.ConnectException)

Example 3 with NotAllowedException

use of org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException in project pulsar by apache.

the class BaseResource method getApiException.

public PulsarAdminException getApiException(Throwable e) {
    if (e instanceof PulsarAdminException) {
        return (PulsarAdminException) e;
    } else if (e instanceof ServiceUnavailableException) {
        if (e.getCause() instanceof java.net.ConnectException) {
            return new ConnectException(e.getCause());
        } else {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new PulsarAdminException(e, httpError, statusCode);
        }
    } else if (e instanceof WebApplicationException) {
        // Handle 5xx exceptions
        if (e instanceof ServerErrorException) {
            ServerErrorException see = (ServerErrorException) e;
            int statusCode = see.getResponse().getStatus();
            String httpError = getReasonFromServer(see);
            return new ServerSideErrorException(see, e.getMessage(), httpError, statusCode);
        } else if (e instanceof ClientErrorException) {
            // Handle 4xx exceptions
            ClientErrorException cee = (ClientErrorException) e;
            int statusCode = cee.getResponse().getStatus();
            String httpError = getReasonFromServer(cee);
            switch(statusCode) {
                case 401:
                case 403:
                    return new NotAuthorizedException(cee, httpError, statusCode);
                case 404:
                    return new NotFoundException(cee, httpError, statusCode);
                case 405:
                    return new NotAllowedException(cee, httpError, statusCode);
                case 409:
                    return new ConflictException(cee, httpError, statusCode);
                case 412:
                    return new PreconditionFailedException(cee, httpError, statusCode);
                default:
                    return new PulsarAdminException(httpError, cee, httpError, statusCode);
            }
        } else {
            WebApplicationException wae = (WebApplicationException) e;
            int statusCode = wae.getResponse().getStatus();
            String httpError = getReasonFromServer(wae);
            return new PulsarAdminException(httpError, wae, httpError, statusCode);
        }
    } else {
        return new PulsarAdminException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) NotAllowedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) NotAuthorizedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) ServerSideErrorException(org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ServerErrorException(javax.ws.rs.ServerErrorException) ConnectException(org.apache.pulsar.client.admin.PulsarAdminException.ConnectException)

Aggregations

ClientErrorException (javax.ws.rs.ClientErrorException)3 ServerErrorException (javax.ws.rs.ServerErrorException)3 ServiceUnavailableException (javax.ws.rs.ServiceUnavailableException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)3 ConflictException (org.apache.pulsar.client.admin.PulsarAdminException.ConflictException)3 ConnectException (org.apache.pulsar.client.admin.PulsarAdminException.ConnectException)3 NotAllowedException (org.apache.pulsar.client.admin.PulsarAdminException.NotAllowedException)3 NotAuthorizedException (org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException)3 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)3 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)3 ServerSideErrorException (org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException)3