Skip to content

[sdk/client] - parsing error text from OData contain the raw details message #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ type Client struct {
ResponseMiddlewares *[]ResponseMiddleware
}

type rawDetailsError struct {
Message string `json:"message"`
}

// NewClient returns a new Client configured with sensible defaults
func NewClient(baseUri string, serviceName, apiVersion string) *Client {
segments := []string{
Expand Down Expand Up @@ -558,6 +562,18 @@ func (c *Client) Execute(ctx context.Context, req *Request) (*Response, error) {
switch {
case resp.OData != nil && resp.OData.Error != nil && resp.OData.Error.String() != "":
errText = fmt.Sprintf("error: %s", resp.OData.Error)
if rawDetails := resp.OData.Error.RawDetails; rawDetails != nil {
var rawDetailsErr []rawDetailsError
if err = json.Unmarshal(*rawDetails, &rawDetailsErr); err == nil {
messages := []string{}
for _, v := range rawDetailsErr {
if v.Message != "" {
messages = append(messages, v.Message)
}
}
errText += strings.Join(messages, "\n")
}
}

default:
defer resp.Body.Close()
Expand Down
Loading