Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
refactor: more informative error on /api/v0/dht/get failure
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored and lidel committed Mar 29, 2023
1 parent 132a62e commit 36568b0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ func (ps *proxyRouting) fetch(ctx context.Context, key string) (rb []byte, err e
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("routing/get RPC returned unexpected status: %s", resp.Status)
}

rb, err = io.ReadAll(resp.Body)
// Read at most 10 KiB (max size of IPNS record).
rb, err = io.ReadAll(io.LimitReader(resp.Body, 10240))
if err != nil {
return nil, err
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("routing/get RPC returned unexpected status: %s, body: %q", resp.Status, string(rb))
}

parts := bytes.Split(bytes.TrimSpace(rb), []byte("\n"))
var b64 string

Expand Down

0 comments on commit 36568b0

Please sign in to comment.