1
1
import type { ChatRateLimit , RateLimit } from "./types" ;
2
2
import type { FailureFunctionPayload , Step } from "./workflow/types" ;
3
3
4
+ const RATELIMIT_STATUS = 429 ;
5
+
4
6
/**
5
7
* Result of 500 Internal Server Error
6
8
*/
7
9
export class QstashError extends Error {
8
- constructor ( message : string ) {
10
+ public readonly status ?: number ;
11
+
12
+ constructor ( message : string , status ?: number ) {
9
13
super ( message ) ;
10
14
this . name = "QstashError" ;
15
+ this . status = status ;
11
16
}
12
17
}
13
18
@@ -17,7 +22,7 @@ export class QstashRatelimitError extends QstashError {
17
22
public reset : string | null ;
18
23
19
24
constructor ( args : RateLimit ) {
20
- super ( `Exceeded burst rate limit. ${ JSON . stringify ( args ) } ` ) ;
25
+ super ( `Exceeded burst rate limit. ${ JSON . stringify ( args ) } ` , RATELIMIT_STATUS ) ;
21
26
this . name = "QstashRatelimitError" ;
22
27
this . limit = args . limit ;
23
28
this . remaining = args . remaining ;
@@ -34,7 +39,7 @@ export class QstashChatRatelimitError extends QstashError {
34
39
public resetTokens : string | null ;
35
40
36
41
constructor ( args : ChatRateLimit ) {
37
- super ( `Exceeded chat rate limit. ${ JSON . stringify ( args ) } ` ) ;
42
+ super ( `Exceeded chat rate limit. ${ JSON . stringify ( args ) } ` , RATELIMIT_STATUS ) ;
38
43
this . name = "QstashChatRatelimitError" ;
39
44
this . limitRequests = args [ "limit-requests" ] ;
40
45
this . limitTokens = args [ "limit-tokens" ] ;
@@ -51,7 +56,7 @@ export class QstashDailyRatelimitError extends QstashError {
51
56
public reset : string | null ;
52
57
53
58
constructor ( args : RateLimit ) {
54
- super ( `Exceeded daily rate limit. ${ JSON . stringify ( args ) } ` ) ;
59
+ super ( `Exceeded daily rate limit. ${ JSON . stringify ( args ) } ` , RATELIMIT_STATUS ) ;
55
60
this . name = "QstashDailyRatelimitError" ;
56
61
this . limit = args . limit ;
57
62
this . remaining = args . remaining ;
0 commit comments