Skip to content

Commit 350e54a

Browse files
committed
Return response body when decoding fails
1 parent 677dd48 commit 350e54a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

composite/graph/graph.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io"
89
"net/http"
910

1011
"github.com/namely/go-sfdc/v3/session"
@@ -67,9 +68,16 @@ func Do(ctx context.Context, session session.ServiceFormatter, graph Request) (*
6768
}
6869
defer resp.Body.Close()
6970

71+
respBody, err := io.ReadAll(resp.Body)
72+
if err != nil {
73+
return nil, fmt.Errorf("error reading Salesforce response: %w", err)
74+
}
7075
graphResp := &Response{}
71-
err = json.NewDecoder(resp.Body).Decode(graphResp)
72-
return graphResp, err
76+
err = json.Unmarshal(respBody, graphResp)
77+
if err != nil {
78+
return nil, fmt.Errorf("unexpected Salesforce response (%d): %s", resp.StatusCode, string(respBody))
79+
}
80+
return graphResp, nil
7381
}
7482

7583
// SuccessResponseBody defines the structure of the composite response body when

0 commit comments

Comments
 (0)