Clean up and start work on Epiphany plugin

This commit is contained in:
Lucien Greathouse
2018-12-03 13:54:54 -08:00
parent 75359e2b83
commit dd4d542d7e
3 changed files with 71 additions and 17 deletions

View File

@@ -18,38 +18,47 @@ local Http = {}
function Http.get(url)
dprint("\nGET", url)
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
return HttpService:GetAsync(url, true)
coroutine.wrap(function()
local success, response = pcall(function()
return HttpService:RequestAsync({
Url = url,
Method = "GET",
})
end)
if ok then
dprint("\t", result)
resolve(HttpResponse.new(result))
if success then
dprint("\t", response)
resolve(HttpResponse.fromRobloxResponse(response))
else
reject(HttpError.fromErrorString(result))
reject(HttpError.fromErrorString(response))
end
end)
end)()
end)
end
function Http.post(url, body)
dprint("\nPOST", url)
dprint(body)
dprint(body);
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
return HttpService:PostAsync(url, body)
coroutine.wrap(function()
local success, response = pcall(function()
return HttpService:RequestAsync({
Url = url,
Method = "POST",
Body = body,
})
end)
if ok then
dprint("\t", result)
resolve(HttpResponse.new(result))
if success then
dprint("\t", response)
resolve(HttpResponse.fromRobloxResponse(response))
else
reject(HttpError.fromErrorString(result))
reject(HttpError.fromErrorString(response))
end
end)
end)()
end)
end