public void handleError()

in profitbricks-rest/src/main/java/org/apache/jclouds/profitbricks/rest/handlers/ProfitBricksHttpErrorHandler.java [43:85]


   public void handleError(final HttpCommand command, final HttpResponse response) {
      Exception exception = null;
      try {
         switch (response.getStatusCode()) {
            case 400:
            case 405:
            case 422:
               exception = new IllegalArgumentException(response.getMessage(), exception);
               break;
            case 401:
               exception = new AuthorizationException("This request requires authentication.", exception);
               break;
            case 402:
            case 409:
               exception = new IllegalStateException(response.getMessage(), exception);
               break;
            case 404:
            case 410:
               if (!command.getCurrentRequest().getMethod().equals("DELETE"))
                  exception = new ResourceNotFoundException(response.getMessage(), exception);
               break;
            case 429:
               exception = new ProfitBricksRateLimitExceededException(response);
               break;
            case 413:
            case 503:
               // if nothing (default message was OK) was parsed from command executor, assume it was an 503 (Maintenance) html response.
               if (response.getMessage().equals("OK"))
                  exception = new HttpResponseException("The ProfitBricks team is currently carrying out maintenance.", command, response);
               else
                  exception = new InsufficientResourcesException(response.getMessage(), exception);
               break;
            default:
               String message = parseMessage(response);
               exception = message == null ? new HttpResponseException(command, response) : new HttpResponseException(
                     command, response, message);
               break;
               
         }
      } finally {
         command.setException(exception);
      }
   }