How Promises Are Created
You never construct Promises manually — they are returned directly by the async network methods. Understanding what they resolve and reject with lets you handle both cases correctly.
Source methods
Each of the four Async request methods returns a Promise:
What the Promise resolves with
When the server responds successfully (the handler calls res:Send(data)), the Promise resolves with the full NetworkResponse table. The resolved value passed to your :Then() callback is that table.
network:GetAsync("player/123")
:Then(function(res)
-- res is the full NetworkResponse
print(res.type) -- "success"
print(res.status) -- e.g. 200
print(res.data) -- whatever the server sent
print(res.message) -- nil on success
end)
NetworkResponse fields (resolved)
| Field | Type | Value on success |
|---|---|---|
type | string | "success" |
status | number? | Code from res:Status() on server, or nil if not set. |
data | any? | Payload from res:Send(data) on server. |
message | string? | nil on success. |
compressed | boolean? | true if auto-decompressed from Deflate. |
What the Promise rejects with
When the server returns an error (the handler calls res:Error(message)), or the request times out after all retry attempts, the Promise rejects. The value passed to :Catch() is also a NetworkResponse table — but with type == "error" or type == "timeout".
network:GetAsync("player/999")
:Then(function(res) UI:Load(res.data) end)
:Catch(function(err)
-- err is a NetworkResponse with type == "error" or "timeout"
if err.type == "timeout" then
warn("Request timed out")
else
warn("Server error:", err.message)
end
end)
NetworkResponse fields (rejected)
| Field | Type | Value on error/timeout |
|---|---|---|
type | string | "error" or "timeout" |
status | number? | Code from res:Status() on server if it called Error. nil on timeout. |
data | any? | nil |
message | string? | Message from res:Error(message), or a built-in rejection message from middleware. |
Full resolve/reject example
network:PostAsync("shop/buy", { itemId = 42 })
:Then(function(res)
-- server called res:Status(200):Send({ newBalance = 850 })
CoinDisplay:Set(res.data.newBalance)
end)
:Catch(function(err)
if err.type == "error" then
-- server called res:Error("Not enough coins")
UI:ShowError(err.message)
elseif err.type == "timeout" then
UI:ShowError("Server not responding — try again")
end
end)
See also
← Promise · Chaining | Then, Catch, Finally reference · Async / Promise API | all four async methods · NetworkResponse type | full field reference