Skip to content

Commit 5a90301

Browse files
committed
More detailed error responses
I've seen this particular error come through a number of times, and it would be useful to get more information about what exactly is happening.
1 parent 350e54a commit 5a90301

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

composite/graph/graph.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910
"net/http"
11+
"strings"
1012

1113
"github.com/namely/go-sfdc/v3/session"
1214
)
@@ -75,6 +77,14 @@ func Do(ctx context.Context, session session.ServiceFormatter, graph Request) (*
7577
graphResp := &Response{}
7678
err = json.Unmarshal(respBody, graphResp)
7779
if err != nil {
80+
if strings.Contains(err.Error(), "unmarshal array") {
81+
trimLength := 1000
82+
if trimLength > len(respBody)-1 {
83+
trimLength = len(respBody) - 1
84+
}
85+
trimmed := string(respBody[0:trimLength])
86+
return nil, errors.New("SFDC Produced an unexpected array response: " + trimmed)
87+
}
7888
return nil, fmt.Errorf("unexpected Salesforce response (%d): %s", resp.StatusCode, string(respBody))
7989
}
8090
return graphResp, nil

0 commit comments

Comments
 (0)