Package twitter4j
Class TwitterException
java.lang.Object
java.lang.Throwable
java.lang.Exception
twitter4j.TwitterException
- All Implemented Interfaces:
Serializable
,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.
In case the Twitter server returned HTTP error code, you can get the HTTP status code using getStatusCode() method.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface twitter4j.TwitterResponse
TwitterResponse.AccessLevel
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Twitter is down or being upgraded.static final int
Bad Request: The request was invalid.static final int
Enhance Your Calm: Returned by the Search and Trends API when you are being rate limited.static final int
Forbidden: The request is understood, but it has been refused.static final int
//static final int
The Twitter servers are up, but the request couldn't be serviced due to some failure within our stack.static final int
Internal Server Error: Something is broken.static final int
//static final int
Not Acceptable: Returned by the Search API when an invalid format is specified in the request.static final int
Not Found: The URI requested is invalid or the resource requested, such as a user, does not exist.static final int
Not Modified: There was no new data to return.static final int
OK: Success!static final int
Service Unavailable: The Twitter servers are up, but overloaded with requests.static final int
Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource.static final int
Not Authorized: Authentication credentials were missing or incorrect.static final int
Returned when an image uploaded to POST account/update_profile_banner is unable to be processed. -
Constructor Summary
ConstructorDescriptionTwitterException
(Exception cause) TwitterException
(String message) TwitterException
(String message, Exception cause, int statusCode) TwitterException
(String message, Throwable cause) TwitterException
(String message, twitter4j.HttpResponse res) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Tests if the exception is caused by rate limitation exceedint
Returns error message from the API if available.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 causeReturns the current rate limit status if available.getResponseHeader
(String name) int
Returns int value of "Retry-After" response header (Search API) or seconds_until_reset (REST API).int
int
hashCode()
boolean
Tests if the exception is caused by network issueboolean
Tests if error message from the API is availableboolean
Tests if the exception is caused by non-existing resourcetoString()
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Field Details
-
OK
static final int OKOK: 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_MODIFIEDNot Modified: There was no new data to return.- See Also:
-
BAD_REQUEST
static final int BAD_REQUESTBad 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 UNAUTHORIZEDNot Authorized: Authentication credentials were missing or incorrect.- See Also:
-
FORBIDDEN
static final int FORBIDDENForbidden: The request is understood, but it has been refused. An accompanying error message will explain why.- See Also:
-
NOT_FOUND
static final int NOT_FOUNDNot 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_ACCEPTABLENot 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_CLAIMEnhance 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_ENTITYReturned 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_REQUESTSReturned 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_ERRORInternal Server Error: Something is broken. Please post to the group so the Twitter team can investigate.- See Also:
-
BAD_GATEWAY
static final int BAD_GATEWAYTwitter is down or being upgraded.- See Also:
-
SERVICE_UNAVAILABLE
static final int SERVICE_UNAVAILABLEService 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_TIMEOUTThe 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
- Parameters:
message
- messagecause
- cause
-
TwitterException
- Parameters:
message
- message
-
TwitterException
- Parameters:
cause
- cause
-
TwitterException
- Parameters:
message
- messageres
- response
-
TwitterException
- Parameters:
message
- messagecause
- causestatusCode
- status code
-
-
Method Details
-
getMessage
- Overrides:
getMessage
in classThrowable
-
getStatusCode
public int getStatusCode()- Returns:
- status code
-
getErrorCode
public int getErrorCode()- Returns:
- error code
-
getResponseHeader
- Parameters:
name
- header name- Returns:
- response header
-
getRateLimitStatus
Description copied from interface:TwitterResponse
Returns the current rate limit status if available.- Specified by:
getRateLimitStatus
in interfaceTwitterResponse
- Returns:
- current rate limit status
-
getAccessLevel
- Specified by:
getAccessLevel
in interfaceTwitterResponse
- 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
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
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
-
hashCode
public int hashCode() -
toString
-