infura requester: properly handle failure
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"iter"
|
"iter"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -21,8 +22,9 @@ type InfuraRequester struct {
|
|||||||
baseURL string
|
baseURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
// dev: http://ucan-issuer-api.commercial-dev.eks-dev.infura.org/
|
// NewInfuraRequester create a requester client for the Infura UCAN token issuer.
|
||||||
// prod:
|
// dev: http://ucan-issuer-api.commercial-dev.eks-dev.infura.org
|
||||||
|
// prod: http://ucan-issuer-api.commercial-prod.eks.infura.org
|
||||||
func NewInfuraRequester(baseURL string) *InfuraRequester {
|
func NewInfuraRequester(baseURL string) *InfuraRequester {
|
||||||
return &InfuraRequester{baseURL: baseURL}
|
return &InfuraRequester{baseURL: baseURL}
|
||||||
}
|
}
|
||||||
@@ -55,6 +57,13 @@ func (i InfuraRequester) RequestDelegation(ctx context.Context, audience did.DID
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
msg, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("request failed with status %d, then failed to read response body: %w", res.StatusCode, err)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("request failed with status %d: %s", res.StatusCode, msg)
|
||||||
|
}
|
||||||
|
|
||||||
resp := struct {
|
resp := struct {
|
||||||
Cid string `json:"cid"`
|
Cid string `json:"cid"`
|
||||||
|
|||||||
Reference in New Issue
Block a user