1
0
mirror of https://github.com/taigrr/wasm-experiments synced 2025-01-18 04:03:21 -08:00

Use callback value to fix panic!

This commit is contained in:
Johan Brandhorst 2018-05-12 21:36:27 +01:00
parent 8e3e7d54de
commit b4fb14ace9
No known key found for this signature in database
GPG Key ID: 266C7D9B44EAA057

View File

@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"syscall/js"
@ -51,7 +52,11 @@ func Fetch(req *Request) (*Response, error) {
case GET, HEAD:
return nil, errors.New("cannot use body with GET or HEAD HTTP methods")
}
init.Set("body", req.Body)
b, err := ioutil.ReadAll(req.Body)
if err != nil {
return nil, err
}
init.Set("body", b)
}
headers := js.Global.Get("Headers").New()
@ -67,6 +72,6 @@ func Fetch(req *Request) (*Response, error) {
})
promise := js.Global.Call("fetch", req.URL.String(), init)
promise.Call("then", cb)
promise.Call("then", cb.Value)
return &Response{}, nil
}