Improve plugin accuracy

This commit is contained in:
Lucien Greathouse
2017-12-01 00:18:11 -08:00
parent c7171ef513
commit 5e64773784
4 changed files with 73 additions and 33 deletions

View File

@@ -1,9 +1,17 @@
local HttpService = game:GetService("HttpService")
local HTTP_DEBUG = false
local Promise = require(script.Parent.Promise)
local HttpError = require(script.Parent.HttpError)
local HttpResponse = require(script.Parent.HttpResponse)
local function dprint(...)
if HTTP_DEBUG then
print(...)
end
end
local Http = {}
Http.__index = Http
@@ -20,6 +28,7 @@ function Http.new(baseUrl)
end
function Http:get(endpoint)
dprint("\nGET", endpoint)
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
@@ -27,6 +36,7 @@ function Http:get(endpoint)
end)
if ok then
dprint("\t", result, "\n")
resolve(HttpResponse.new(result))
else
reject(HttpError.fromErrorString(result))
@@ -36,6 +46,8 @@ function Http:get(endpoint)
end
function Http:post(endpoint, body)
dprint("\nPOST", endpoint)
dprint(body)
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
@@ -43,6 +55,7 @@ function Http:post(endpoint, body)
end)
if ok then
dprint("\t", result, "\n")
resolve(HttpResponse.new(result))
else
reject(HttpError.fromErrorString(result))