mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-21 06:12:02 +02:00
nip11 fetch better errors.
This commit is contained in:
parent
f3c081fcd6
commit
8a540998b9
@ -25,7 +25,7 @@ func Fetch(ctx context.Context, u string) (info *RelayInformationDocument, err e
|
|||||||
}
|
}
|
||||||
p, err := url.Parse(u)
|
p, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Cannot parse url: %s", u)
|
return nil, fmt.Errorf("cannot parse url: %s", u)
|
||||||
}
|
}
|
||||||
if p.Scheme == "ws" {
|
if p.Scheme == "ws" {
|
||||||
p.Scheme = "http"
|
p.Scheme = "http"
|
||||||
@ -42,11 +42,14 @@ func Fetch(ctx context.Context, u string) (info *RelayInformationDocument, err e
|
|||||||
// send the request
|
// send the request
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("request failed: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
info = &RelayInformationDocument{}
|
info = &RelayInformationDocument{}
|
||||||
dec := json.NewDecoder(resp.Body)
|
if err := json.NewDecoder(resp.Body).Decode(info); err != nil {
|
||||||
err = dec.Decode(info)
|
return nil, fmt.Errorf("invalid json: %w", err)
|
||||||
return info, err
|
}
|
||||||
|
|
||||||
|
return info, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user