Package twitter4j

Class TwitterException

All Implemented Interfaces:
Serializable, TwitterResponse

public class TwitterException extends Exception implements TwitterResponse
An exception class that will be thrown when TwitterAPI calls are failed.
In case the Twitter server returned HTTP error code, you can get the HTTP status code using getStatusCode() method.
See Also:
  • Field Details

    • OK

      static final int OK
      OK: Success!
      See Also:
    • MULTIPLE_CHOICES

      static final int MULTIPLE_CHOICES
      //
      See Also:
    • FOUND

      static final int FOUND
      //
      See Also:
    • NOT_MODIFIED

      static final int NOT_MODIFIED
      Not Modified: There was no new data to return.
      See Also:
    • BAD_REQUEST

      static final int BAD_REQUEST
      Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting.
      See Also:
    • UNAUTHORIZED

      static final int UNAUTHORIZED
      Not Authorized: Authentication credentials were missing or incorrect.
      See Also:
    • FORBIDDEN

      static final int FORBIDDEN
      Forbidden: The request is understood, but it has been refused. An accompanying error message will explain why.
      See Also:
    • NOT_FOUND

      static final int NOT_FOUND
      Not Found: The URI requested is invalid or the resource requested, such as a user, does not exist.
      See Also:
    • NOT_ACCEPTABLE

      static final int NOT_ACCEPTABLE
      Not Acceptable: Returned by the Search API when an invalid format is specified in the request.
      See Also:
    • ENHANCE_YOUR_CLAIM

      static final int ENHANCE_YOUR_CLAIM
      Enhance Your Calm: Returned by the Search and Trends API when you are being rate limited. Not registered in RFC.
      See Also:
    • UNPROCESSABLE_ENTITY

      static final int UNPROCESSABLE_ENTITY
      Returned when an image uploaded to POST account/update_profile_banner is unable to be processed.
      See Also:
    • TOO_MANY_REQUESTS

      static final int TOO_MANY_REQUESTS
      Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource. See Rate Limiting in API v1.1.
      See Also:
    • INTERNAL_SERVER_ERROR

      static final int INTERNAL_SERVER_ERROR
      Internal Server Error: Something is broken. Please post to the group so the Twitter team can investigate.
      See Also:
    • BAD_GATEWAY

      static final int BAD_GATEWAY
      Twitter is down or being upgraded.
      See Also:
    • SERVICE_UNAVAILABLE

      static final int SERVICE_UNAVAILABLE
      Service Unavailable: The Twitter servers are up, but overloaded with requests. Try again later. The search and trend methods use this to indicate when you are being rate limited.
      See Also:
    • GATEWAY_TIMEOUT

      static final int GATEWAY_TIMEOUT
      The Twitter servers are up, but the request couldn't be serviced due to some failure within our stack. Try again later.
      See Also:
  • Constructor Details

    • TwitterException

      public TwitterException(String message, Throwable cause)
      Parameters:
      message - message
      cause - cause
    • TwitterException

      public TwitterException(String message)
      Parameters:
      message - message
    • TwitterException

      public TwitterException(Exception cause)
      Parameters:
      cause - cause
    • TwitterException

      public TwitterException(String message, twitter4j.HttpResponse res)
      Parameters:
      message - message
      res - response
    • TwitterException

      public TwitterException(String message, Exception cause, int statusCode)
      Parameters:
      message - message
      cause - cause
      statusCode - status code
  • Method Details

    • getMessage

      public String getMessage()
      Overrides:
      getMessage in class Throwable
    • getStatusCode

      public int getStatusCode()
      Returns:
      status code
    • getErrorCode

      public int getErrorCode()
      Returns:
      error code
    • getResponseHeader

      public String getResponseHeader(String name)
      Parameters:
      name - header name
      Returns:
      response header
    • getRateLimitStatus

      public RateLimitStatus getRateLimitStatus()
      Description copied from interface: TwitterResponse
      Returns the current rate limit status if available.
      Specified by:
      getRateLimitStatus in interface TwitterResponse
      Returns:
      current rate limit status
    • getAccessLevel

      public TwitterResponse.AccessLevel getAccessLevel()
      Specified by:
      getAccessLevel in interface TwitterResponse
      Returns:
      application permission model
      See Also:
    • getRetryAfter

      public int getRetryAfter()
      Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST API). An application that exceeds the rate limitations of the Search API will receive HTTP 420 response codes to requests. It is a best practice to watch for this error condition and honor the Retry-After header that instructs the application when it is safe to continue. The Retry-After header's value is the number of seconds your application should wait before submitting another query (for example: Retry-After: 67).
      Check if getStatusCode() == 503 before calling this method to ensure that you are actually exceeding rate limitation with query apis.
      Returns:
      instructs the application when it is safe to continue in seconds
      Since:
      Twitter4J 2.1.0
      See Also:
    • isCausedByNetworkIssue

      public boolean isCausedByNetworkIssue()
      Tests if the exception is caused by network issue
      Returns:
      if the exception is caused by network issue
      Since:
      Twitter4J 2.1.2
    • exceededRateLimitation

      public boolean exceededRateLimitation()
      Tests if the exception is caused by rate limitation exceed
      Returns:
      if the exception is caused by rate limitation exceed
      Since:
      Twitter4J 2.1.2
      See Also:
    • resourceNotFound

      public boolean resourceNotFound()
      Tests if the exception is caused by non-existing resource
      Returns:
      if the exception is caused by non-existing resource
      Since:
      Twitter4J 2.1.2
    • getExceptionCode

      public String getExceptionCode()
      Returns a hexadecimal representation of this exception stacktrace.
      An exception code is a hexadecimal representation of the stacktrace which enables it easier to Google known issues.
      Format : XXXXXXXX:YYYYYYYY[ XX:YY]
      Where XX is a hash code of stacktrace without line number
      YY is a hash code of stacktrace excluding line number
      [-XX:YY] will appear when this instance a root cause
      Returns:
      a hexadecimal representation of this exception stacktrace
    • getErrorMessage

      public String getErrorMessage()
      Returns error message from the API if available.
      Returns:
      error message from the API
      Since:
      Twitter4J 2.2.3
    • isErrorMessageAvailable

      public boolean isErrorMessageAvailable()
      Tests if error message from the API is available
      Returns:
      true if error message from the API is available
      Since:
      Twitter4J 2.2.3
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Throwable