twitter4j
Class TwitterException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by twitter4j.TwitterException
All Implemented Interfaces:
java.io.Serializable, twitter4j.internal.http.HttpResponseCode, TwitterResponse

public class TwitterException
extends java.lang.Exception
implements TwitterResponse, twitter4j.internal.http.HttpResponseCode

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.

Author:
Yusuke Yamamoto - yusuke at mac.com
See Also:
Serialized Form

Field Summary
private  ExceptionDiagnosis exceptionDiagnosis
           
private  RateLimitStatus featureSpecificRateLimitStatus
           
private static java.lang.String[] FILTER
           
(package private)  boolean nested
           
private  RateLimitStatus rateLimitStatus
           
private  java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields
           
private  int retryAfter
           
private static long serialVersionUID
           
private  int statusCode
           
 
Fields inherited from interface twitter4j.internal.http.HttpResponseCode
BAD_GATEWAY, BAD_REQUEST, ENHANCE_YOUR_CLAIM, FORBIDDEN, FOUND, INTERNAL_SERVER_ERROR, MULTIPLE_CHOICES, NOT_ACCEPTABLE, NOT_FOUND, NOT_MODIFIED, OK, SERVICE_UNAVAILABLE, TOO_LONG, UNAUTHORIZED
 
Constructor Summary
TwitterException(java.lang.Exception cause)
           
TwitterException(java.lang.String message)
           
TwitterException(java.lang.String msg, java.lang.Exception cause)
           
TwitterException(java.lang.String msg, java.lang.Exception cause, int statusCode)
           
TwitterException(java.lang.String message, twitter4j.internal.http.HttpResponse res)
           
TwitterException(java.lang.String message, int retryAfter, java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields, int statusCode, RateLimitStatus rateLimitStatus, RateLimitStatus featureSpecificLateLimitStatus)
           
 
Method Summary
private static java.lang.String decode(java.lang.String str)
           
 boolean equals(java.lang.Object o)
           
 boolean exceededRateLimitation()
          Tests if the exception is caused by rate limitation exceed
private static java.lang.String getCause(twitter4j.internal.http.HttpResponse res)
           
 java.lang.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
private  ExceptionDiagnosis getExceptionDiagnosis()
           
 RateLimitStatus getFeatureSpecificRateLimitStatus()
          Returns the current feature-specific rate limit status if available.
This method is available in conjunction with Twitter#searchUsers()
 RateLimitStatus getRateLimitStatus()
          Returns the current rate limit status if available.
 java.lang.String getResponseHeader(java.lang.String name)
           
 int getRetryAfter()
          Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST API).
 int getStatusCode()
           
 int hashCode()
           
 boolean isCausedByNetworkIssue()
          Tests if the exception is caused by network issue
 boolean resourceNotFound()
          Tests if the exception is caused by non-existing resource
(package private)  void setNested()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

statusCode

private int statusCode

retryAfter

private int retryAfter

rateLimitStatus

private RateLimitStatus rateLimitStatus

featureSpecificRateLimitStatus

private RateLimitStatus featureSpecificRateLimitStatus

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

responseHeaderFields

private java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields

exceptionDiagnosis

private ExceptionDiagnosis exceptionDiagnosis

FILTER

private static final java.lang.String[] FILTER

nested

boolean nested
Constructor Detail

TwitterException

public TwitterException(java.lang.String message)

TwitterException

public TwitterException(java.lang.Exception cause)

TwitterException

public TwitterException(java.lang.String message,
                        twitter4j.internal.http.HttpResponse res)

TwitterException

public TwitterException(java.lang.String message,
                        int retryAfter,
                        java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields,
                        int statusCode,
                        RateLimitStatus rateLimitStatus,
                        RateLimitStatus featureSpecificLateLimitStatus)
Parameters:
message - message
retryAfter - retry-after
responseHeaderFields - response header fields
statusCode - status code
rateLimitStatus - rate limit status
featureSpecificLateLimitStatus - feature specific rate limit status
Since:
Twitter4J 2.1.9

TwitterException

public TwitterException(java.lang.String msg,
                        java.lang.Exception cause)

TwitterException

public TwitterException(java.lang.String msg,
                        java.lang.Exception cause,
                        int statusCode)
Method Detail

decode

private static java.lang.String decode(java.lang.String str)

getStatusCode

public int getStatusCode()

getResponseHeader

public java.lang.String getResponseHeader(java.lang.String name)

getRateLimitStatus

public RateLimitStatus getRateLimitStatus()
Returns the current rate limit status if available.

Specified by:
getRateLimitStatus in interface TwitterResponse
Returns:
current rate limit status
Since:
Twitter4J 2.1.2

getFeatureSpecificRateLimitStatus

public RateLimitStatus getFeatureSpecificRateLimitStatus()
Returns the current feature-specific rate limit status if available.
This method is available in conjunction with Twitter#searchUsers()

Returns:
current rate limit status
Since:
Twitter4J 2.1.2
See Also:
Rate limiting

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.
Otherwise, you'll get an IllegalStateException if "Retry-After" response header was not included in the response.

Returns:
instructs the application when it is safe to continue in seconds
Since:
Twitter4J 2.1.0
See Also:
Rate limiting

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:
Rate limiting

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 java.lang.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

getExceptionDiagnosis

private ExceptionDiagnosis getExceptionDiagnosis()

setNested

void setNested()

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Throwable

getCause

private static java.lang.String getCause(twitter4j.internal.http.HttpResponse res)