root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / winterwell / jtwitter / TwitterException.java @ 59
History | View | Annotate | Download (3.88 KB)
1 |
package winterwell.jtwitter; |
---|---|
2 |
|
3 |
|
4 |
/**
|
5 |
* A runtime exception for when Twitter requests don't work. All {@link Twitter} methods can throw this.
|
6 |
* <p>
|
7 |
* This contains several subclasses which should be thrown to mark different problems. Error handling is particularly important as
|
8 |
* Twitter tends to be a bit flaky.
|
9 |
* <p>
|
10 |
* I believe unchecked exceptions are preferable to checked ones, because they avoid the problems caused by swallowing exceptions.
|
11 |
* But if you don't like runtime exceptions, just edit this class.
|
12 |
*
|
13 |
* @author Daniel Winterstein
|
14 |
*/
|
15 |
@SuppressWarnings("all") |
16 |
public class TwitterException |
17 |
extends
|
18 |
RuntimeException {
|
19 |
|
20 |
/**
|
21 |
* Something has gone wrong. Occasionally Twitter behaves strangely.
|
22 |
*/
|
23 |
public static class Unexplained |
24 |
extends
|
25 |
TwitterException { |
26 |
public Unexplained(final String msg) { |
27 |
super(msg);
|
28 |
} |
29 |
|
30 |
private static final long serialVersionUID = 1L; |
31 |
} |
32 |
|
33 |
/**
|
34 |
* A timeout exception - probably caused by Twitter being overloaded.
|
35 |
*/
|
36 |
public static class Timeout |
37 |
extends
|
38 |
TwitterException { |
39 |
public Timeout(final String string) { |
40 |
super(string);
|
41 |
} |
42 |
|
43 |
private static final long serialVersionUID = 1L; |
44 |
} |
45 |
/**
|
46 |
* A code 50X error (e.g. 502) - indicating something went wrong at Twitter's end. The API equivalent of the Fail Whale.
|
47 |
* Usually retrying in a minute will fix this.
|
48 |
*/
|
49 |
public static class E50X |
50 |
extends
|
51 |
TwitterException { |
52 |
public E50X(final String string) { |
53 |
super(string);
|
54 |
} |
55 |
|
56 |
private static final long serialVersionUID = 1L; |
57 |
} |
58 |
/**
|
59 |
* A Forbidden exception. This is thrown if the authenticating used does not have the right to make a request.
|
60 |
*/
|
61 |
public static class E403 |
62 |
extends
|
63 |
TwitterException { |
64 |
public E403(final String string) { |
65 |
super(string);
|
66 |
} |
67 |
|
68 |
private static final long serialVersionUID = 1L; |
69 |
} |
70 |
/**
|
71 |
* An unauthorised exception. This is thrown (eg) if a password is wrong or a login is required.
|
72 |
*/
|
73 |
public static class E401 |
74 |
extends
|
75 |
TwitterException { |
76 |
public E401(final String string) { |
77 |
super(string);
|
78 |
} |
79 |
|
80 |
private static final long serialVersionUID = 1L; |
81 |
} |
82 |
|
83 |
|
84 |
private static final long serialVersionUID = 1L; |
85 |
|
86 |
private String additionalInfo = ""; |
87 |
|
88 |
|
89 |
/**
|
90 |
* Wrap an exception as a TwitterException.
|
91 |
*/
|
92 |
TwitterException(final Exception e) { |
93 |
super(e);
|
94 |
// avoid gratuitous nesting of exceptions
|
95 |
assert !(e instanceof TwitterException) : e; |
96 |
} |
97 |
|
98 |
|
99 |
/**
|
100 |
* @param string
|
101 |
*/
|
102 |
public TwitterException(final String string) { |
103 |
super(string);
|
104 |
} |
105 |
|
106 |
|
107 |
public TwitterException(final String string, |
108 |
final String additionalInfo) { |
109 |
this(string);
|
110 |
this.setAdditionalInfo(additionalInfo);
|
111 |
} |
112 |
|
113 |
|
114 |
public void setAdditionalInfo(final String additionalInfo) { |
115 |
this.additionalInfo = additionalInfo;
|
116 |
} |
117 |
|
118 |
|
119 |
public String getAdditionalInfo() { |
120 |
return additionalInfo;
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Indicates a 404: resource does not exist error from Twitter. Note: Can be throw in relation to suspended users.
|
125 |
*/
|
126 |
public static class E404 |
127 |
extends
|
128 |
TwitterException { |
129 |
public E404(final String string) { |
130 |
super(string);
|
131 |
} |
132 |
|
133 |
private static final long serialVersionUID = 1L; |
134 |
} |
135 |
/**
|
136 |
* Indicates a rate limit error (i.e. you've over-used Twitter)
|
137 |
*/
|
138 |
public static class RateLimit |
139 |
extends
|
140 |
TwitterException { |
141 |
public RateLimit(final String string) { |
142 |
super(string);
|
143 |
} |
144 |
|
145 |
private static final long serialVersionUID = 1L; |
146 |
} |
147 |
} |