-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathXeroRateLimitException.java
95 lines (82 loc) · 3.18 KB
/
XeroRateLimitException.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.xero.api;
/**
* Base application exception all other rate limit Xero exceptions should extend
*/
public class XeroRateLimitException extends XeroException {
private static final long serialVersionUID = 1L;
private int statusCode = 0;
private String message;
/**
* The remaining app limit
*/
private final Integer appLimitRemaining;
/**
* The remaining day limit
*/
private final Integer dayLimitRemaining;
/**
* The remaining minute limit
*/
private final Integer minuteLimitRemaining;
/**
* retryAfterSeconds that tells you how many seconds to wait before making another request.
* Requests are counted against a fixed window which will reset at different times for each tenant.
* It is important to use the Retry-After header to know when you can start making calls again.
*/
private final Long retryAfterSeconds;
/** Init XeroRateLimitException
* @param statusCode int the server status code returned.
* @param appLimitRemaining Integer the number of calls remaining for app limit
* @param dayLimitRemaining Integer the number of calls in a 24 hour rolling window remain for an org
* @param minuteLimitRemaining Integer the number of calls in a 60 second rolling window remain for an org
* @param retryAfterSeconds Long the number of seconds to wait before resuming API calls
* @param message String the message pertaining to the rate limit
* @param e Exception object with details about the original exception
*/
public XeroRateLimitException(int statusCode, Integer appLimitRemaining, Integer dayLimitRemaining, Integer minuteLimitRemaining,
Long retryAfterSeconds, String message, Exception e) {
super(statusCode + " : " + message, e);
this.statusCode = statusCode;
this.appLimitRemaining = appLimitRemaining;
this.dayLimitRemaining = dayLimitRemaining;
this.minuteLimitRemaining = minuteLimitRemaining;
this.message = message;
this.retryAfterSeconds = retryAfterSeconds;
}
/** get Status Code
* @return int with server status code.
*/
public int getStatusCode() {
return statusCode;
}
/** get message
* @return Sting with the message pertaining to the rate limit
*/
public String getMessage() {
return message;
}
/** get remaining app limit
* @return Integer the number of calls remaining for app limit
*/
public Integer getAppLimitRemaining() {
return appLimitRemaining;
}
/** get remaining daily limit
* @return Integer the number of calls in a 24 hour rolling window remain for an org
*/
public Integer getDayLimitRemaining() {
return dayLimitRemaining;
}
/** get remaining minute limit
* @return Integer the number of calls in a 60 second rolling window remain for an org
*/
public Integer getMinuteLimitRemaining() {
return minuteLimitRemaining;
}
/** get retry after seconds
* @return Long the number of seconds to wait before resuming API calls
*/
public Long getRetryAfterSeconds() {
return retryAfterSeconds;
}
}