All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.commuty.parking.http.HttpRequestException Maven / Gradle / Ivy

Go to download

This package acts as a client to communicate with the Commuty Parking Access API. It avoids you to deal with HTTP directly and provides you proper data structures to work with the API.

The newest version!
package net.commuty.parking.http;

import static java.net.HttpURLConnection.*;

/**
 * 

This exception will occur when the api accepted the request but returned a HTTP status 400 or above.

*

You can get the HTTP status code via {@link #getHttpResponseCode()}. Some helpers methods are present to handle some cases:

*
    *
  • {@link #isForbidden()}: http status 403
  • *
  • {@link #isUnauthorized()}: http status 401
  • *
  • {@link #isBadRequest()}: http status 400
  • *
*

Sometimes, you will get more information via the {@link #getErrorResponse()} method. This exposes a reason and message property. For more information, consult the api documentation.

*/ public class HttpRequestException extends ApiException { private final int httpResponseCode; private final Error errorResponse; protected HttpRequestException(int httpResponseCode, Error errorResponse) { super("The request failed with an error code "+ httpResponseCode); this.httpResponseCode = httpResponseCode; this.errorResponse = errorResponse; } /** * Returns more information linked with the request exception. Can be null. */ public Error getErrorResponse() { return errorResponse; } /** * Indicates if the request is forbidden (http 403). */ public boolean isForbidden() { return httpResponseCode == HTTP_FORBIDDEN; } /** * Indicates if the request is unauthorized (http 401). */ public boolean isUnauthorized() { return httpResponseCode == HTTP_UNAUTHORIZED; } /** * Indicates if the request is a bad request (http 400). */ public boolean isBadRequest() { return httpResponseCode == HTTP_BAD_REQUEST; } /** * Returns the http status code. */ public int getHttpResponseCode() { return httpResponseCode; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy