@@ -11,6 +11,8 @@ local ApiPaths = require(script.Parent.Parent.Data.ApiPaths)
11
11
local ServerType = require (script .Parent .Parent .Enums .ServerType )
12
12
13
13
local HEARTBEAT_UPDATE_SECONDS = 60 * 10 -- send server heartbeat every 10 minutes.
14
+ local MAX_ATTEMPTS_AT_REQUESTS = 5
15
+ local DELAY_BETWEEN_ATTEMPTS = 1.5
14
16
15
17
local ApiService = {}
16
18
@@ -30,8 +32,6 @@ ApiService.OnAuthenticated = Signal.new()
30
32
31
33
ApiService .Authenticated = State .new (false )
32
34
33
- -- todo: re-queue HTTP requests if they fail!
34
-
35
35
function ApiService ._QueryTraceAsync (self : ApiService )
36
36
return self :RawRequestAsync ({
37
37
Url = `https://{ApiPaths .TraceUrl }` ,
@@ -103,24 +103,40 @@ end
103
103
104
104
function ApiService .RawRequestAsync (self : ApiService , data : { [any ]: any })
105
105
return Promise .new (function (resolve , reject )
106
- local success , response = pcall (HttpService .RequestAsync , HttpService , data )
106
+ local attempts = 0
107
+ local rejectionResponse
107
108
108
- if not success or not response .Success then
109
- local responseIsTable = typeof (response ) == "table"
110
-
111
- return reject ({
112
- Success = responseIsTable and response .Success or success ,
113
- StatusCode = responseIsTable and response .StatusCode or 0 ,
114
- StatusMessage = responseIsTable and response .StatusMessage or response ,
115
- Headers = responseIsTable and response .Headers or {},
116
- Body = responseIsTable and response .Body or HttpService :JSONEncode ({
117
- code = 0 ,
118
- message = response
119
- })
120
- })
109
+ while attempts < MAX_ATTEMPTS_AT_REQUESTS do
110
+ local success , response = pcall (HttpService .RequestAsync , HttpService , data )
111
+
112
+ if not success or not response .Success then
113
+ local responseIsTable = typeof (response ) == "table"
114
+
115
+ rejectionResponse = {
116
+ Success = responseIsTable and response .Success or success ,
117
+ StatusCode = responseIsTable and response .StatusCode or 0 ,
118
+ StatusMessage = responseIsTable and response .StatusMessage or response ,
119
+ Headers = responseIsTable and response .Headers or {},
120
+ Body = responseIsTable and response .Body or HttpService :JSONEncode ({
121
+ code = 0 ,
122
+ message = response
123
+ })
124
+ }
125
+
126
+ self .Reporter :Warn (`Attempt #{attempts } to make a request to '{data .Url }' failed;` )
127
+ self .Reporter :Warn (rejectionResponse )
128
+
129
+ task.wait (DELAY_BETWEEN_ATTEMPTS )
130
+
131
+ attempts += 1
132
+
133
+ continue
134
+ end
135
+
136
+ return resolve (response )
121
137
end
122
138
123
- return resolve ( response )
139
+ return reject ( rejectionResponse )
124
140
end )
125
141
end
126
142
0 commit comments