11package com .auth0 .exception ;
22
3+ import com .auth0 .net .TokenQuotaBucket ;
4+
35import java .util .Map ;
46
57/**
@@ -16,6 +18,10 @@ public class RateLimitException extends APIException {
1618 private final long remaining ;
1719 private final long reset ;
1820
21+ private TokenQuotaBucket clientQuotaLimit ;
22+ private TokenQuotaBucket organizationQuotaLimit ;
23+ private long retryAfter ;
24+
1925 private static final int STATUS_CODE_TOO_MANY_REQUEST = 429 ;
2026
2127 public RateLimitException (long limit , long remaining , long reset , Map <String , Object > values ) {
@@ -56,4 +62,119 @@ public long getReset() {
5662 return reset ;
5763 }
5864
65+ /**
66+ * Getter for the client quota limit.
67+ * @return The client quota limit or null if missing.
68+ */
69+ public TokenQuotaBucket getClientQuotaLimit () {
70+ return clientQuotaLimit ;
71+ }
72+
73+ /**
74+ * Getter for the organization quota limit.
75+ * @return The organization quota limit or null if missing.
76+ */
77+ public TokenQuotaBucket getOrganizationQuotaLimit () {
78+ return organizationQuotaLimit ;
79+ }
80+
81+ /**
82+ * Getter for the retry after time in seconds.
83+ * @return The retry after time in seconds or -1 if missing.
84+ */
85+ public long getRetryAfter () {
86+ return retryAfter ;
87+ }
88+
89+ /**
90+ * Builder class for creating instances of RateLimitException.
91+ */
92+ public static class Builder {
93+ private long limit ;
94+ private long remaining ;
95+ private long reset ;
96+ private TokenQuotaBucket clientQuotaLimit ;
97+ private TokenQuotaBucket organizationQuotaLimit ;
98+ private long retryAfter ;
99+ private Map <String , Object > values ;
100+
101+ /**
102+ * Constructor for the Builder.
103+ * @param limit The maximum number of requests available in the current time frame.
104+ * @param remaining The number of remaining requests in the current time frame.
105+ * @param reset The UNIX timestamp of the expected time when the rate limit will reset.
106+ */
107+ public Builder (long limit , long remaining , long reset ) {
108+ this .limit = limit ;
109+ this .remaining = remaining ;
110+ this .reset = reset ;
111+ }
112+
113+ /**
114+ * Constructor for the Builder.
115+ * @param limit The maximum number of requests available in the current time frame.
116+ * @param remaining The number of remaining requests in the current time frame.
117+ * @param reset The UNIX timestamp of the expected time when the rate limit will reset.
118+ * @param values The values map.
119+ */
120+ public Builder (long limit , long remaining , long reset , Map <String , Object > values ) {
121+ this .limit = limit ;
122+ this .remaining = remaining ;
123+ this .reset = reset ;
124+ this .values = values ;
125+ }
126+
127+ /**
128+ * Sets the client quota limit.
129+ * @param clientQuotaLimit The client quota limit.
130+ * @return The Builder instance.
131+ */
132+ public Builder clientQuotaLimit (TokenQuotaBucket clientQuotaLimit ) {
133+ this .clientQuotaLimit = clientQuotaLimit ;
134+ return this ;
135+ }
136+
137+ /**
138+ * Sets the organization quota limit.
139+ * @param organizationQuotaLimit The organization quota limit.
140+ * @return The Builder instance.
141+ */
142+ public Builder organizationQuotaLimit (TokenQuotaBucket organizationQuotaLimit ) {
143+ this .organizationQuotaLimit = organizationQuotaLimit ;
144+ return this ;
145+ }
146+
147+ /**
148+ * Sets the retry after time in seconds.
149+ * @param retryAfter The retry after time in seconds.
150+ * @return The Builder instance.
151+ */
152+ public Builder retryAfter (long retryAfter ) {
153+ this .retryAfter = retryAfter ;
154+ return this ;
155+ }
156+
157+ /**
158+ * Sets the values map.
159+ * @param values The values map.
160+ * @return The Builder instance.
161+ */
162+ public Builder values (Map <String , Object > values ) {
163+ this .values = values ;
164+ return this ;
165+ }
166+
167+ public RateLimitException build () {
168+ RateLimitException exception = (this .values != null )
169+ ? new RateLimitException (this .limit , this .remaining , this .reset , this .values )
170+ : new RateLimitException (this .limit , this .remaining , this .reset );
171+
172+ exception .clientQuotaLimit = this .clientQuotaLimit ;
173+ exception .organizationQuotaLimit = this .organizationQuotaLimit ;
174+ exception .retryAfter = this .retryAfter ;
175+
176+ return exception ;
177+ }
178+ }
179+
59180}
0 commit comments