@jnode/discord 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/client.js +7 -7
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -60,13 +60,13 @@ class DiscordClient {
|
|
|
60
60
|
'Content-Type': (body !== undefined) ? 'application/json' : null
|
|
61
61
|
}, (body !== undefined) ? JSON.stringify(body) : undefined); //make an request
|
|
62
62
|
|
|
63
|
-
if ((res.
|
|
63
|
+
if ((res.statusCode === 429) && this.apiAutoRetry) { //retry if recieved 429
|
|
64
64
|
await delay(res.json().retry_after);
|
|
65
65
|
return this.apiRequest(method, path, body);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (((res.
|
|
69
|
-
throw new DiscordAPIError(res.
|
|
68
|
+
if (((res.statusCode > 299) || (res.statusCode < 200)) && this.apiThrowError) { //throw error if not 2xx
|
|
69
|
+
throw new DiscordAPIError(res.statusCode, res.json() ?? res.text(), res.headers);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
return res;
|
|
@@ -97,13 +97,13 @@ class DiscordClient {
|
|
|
97
97
|
'User-Agent': 'DiscordBot'
|
|
98
98
|
}, parts); //make an request
|
|
99
99
|
|
|
100
|
-
if ((res.
|
|
100
|
+
if ((res.statusCode === 429) && this.apiAutoRetry) { //retry if recieved 429
|
|
101
101
|
await delay(res.json().retry_after);
|
|
102
102
|
return this.apiRequest(method, path, body, multipart, true);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
if (((res.
|
|
106
|
-
throw new DiscordAPIError(res.
|
|
105
|
+
if (((res.statusCode > 299) || (res.statusCode < 200)) && this.apiThrowError) { //throw error if not 2xx
|
|
106
|
+
throw new DiscordAPIError(res.statusCode, res.json() ?? res.text(), res.headers);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
return res;
|
|
@@ -112,7 +112,7 @@ class DiscordClient {
|
|
|
112
112
|
async connectGateway(cb) {
|
|
113
113
|
await this.gateway.getGatewayUrl();
|
|
114
114
|
this.gateway.connect();
|
|
115
|
-
cb(this.gateway);
|
|
115
|
+
if (cb) cb(this.gateway);
|
|
116
116
|
return this.gateway;
|
|
117
117
|
}
|
|
118
118
|
}
|