diff --git a/plugin/http/Error.lua b/plugin/http/Error.lua index ed85fc674..f9e46b38e 100644 --- a/plugin/http/Error.lua +++ b/plugin/http/Error.lua @@ -3,12 +3,12 @@ Error.__index = Error Error.Kind = { HttpNotEnabled = { - message = "Rojo requires HTTP access, which is not enabled.\n" .. - "Check your game settings, located in the 'Home' tab of Studio.", + message = "Rojo requires HTTP access, which is not enabled.\n" + .. "Check your game settings, located in the 'Home' tab of Studio.", }, ConnectFailed = { - message = "Couldn't connect to the Rojo server.\n" .. - "Make sure the server is running — use 'rojo serve' to run it!", + message = "Couldn't connect to the Rojo server.\n" + .. "Make sure the server is running — use 'rojo serve' to run it!", }, Timeout = { message = "HTTP request timed out.", @@ -63,4 +63,13 @@ function Error.fromRobloxErrorString(message) return Error.new(Error.Kind.Unknown, message) end +function Error.fromResponse(response) + local lower = (response.body or ""):lower() + if response.code == 408 or response.code == 504 or lower:find("timed? ?out") then + return Error.new(Error.Kind.Timeout) + end + + return Error.new(Error.Kind.Unknown, string.format("%s: %s", tostring(response.code), tostring(response.body))) +end + return Error diff --git a/plugin/http/init.lua b/plugin/http/init.lua index 686130ef6..cac0ebc4a 100644 --- a/plugin/http/init.lua +++ b/plugin/http/init.lua @@ -30,8 +30,13 @@ local function performRequest(requestParams) end) if success then - Log.trace("Request {} success, status code {}", requestId, response.StatusCode) - resolve(HttpResponse.fromRobloxResponse(response)) + Log.trace("Request {} success, response {:#?}", requestId, response) + local httpResponse = HttpResponse.fromRobloxResponse(response) + if httpResponse:isSuccess() then + resolve(httpResponse) + else + reject(HttpError.fromResponse(httpResponse)) + end else Log.trace("Request {} failure: {:?}", requestId, response) reject(HttpError.fromRobloxErrorString(response)) @@ -63,4 +68,4 @@ function Http.jsonDecode(source) return HttpService:JSONDecode(source) end -return Http \ No newline at end of file +return Http