File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -30,22 +30,23 @@ local HttpService = game:GetService("HttpService")
3030-- Ideally, you do this once per project per async method that you use.
3131local function httpGet (url )
3232 return Promise .new (function (resolve , reject )
33- local ok , result = pcall (HttpService . GetAsync , HttpService , url )
33+ local result = HttpService : JSONDecode (HttpService : GetAsync ( url ) )
3434
35- if ok then
36- resolve (result )
35+ if result . ok then
36+ resolve (result . data )
3737 else
38- reject (result )
38+ reject (result . error )
3939 end
4040 end )
4141end
4242
4343-- Usage
44- httpGet (" https://google.com " )
44+ httpGet (" https://some-api.example " )
4545 :andThen (function (body )
46- print (" Here's the Google homepage :" , body )
46+ print (" Here's the web api result :" , body )
4747 end )
4848 :catch (function (err )
49- warn (" We failed to get the Google homepage! " , err )
49+ warn (" Web api encountered an error: " , err )
5050 end )
5151```
52+
You can’t perform that action at this time.
0 commit comments