Skip to content

Commit

Permalink
Merge pull request #188 from coinbase/patrick/verbose-client-error
Browse files Browse the repository at this point in the history
[client] Verbose Response Type Error
  • Loading branch information
patrick-ogrady authored Oct 15, 2020
2 parents 978c228 + 80b7e97 commit 0605285
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -228,17 +227,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
if len(b) == 0 {
return nil
}

if s, ok := v.(*string); ok {
*s = string(b)
return nil
}

if jsonCheck.MatchString(contentType) {
if err = json.Unmarshal(b, v); err != nil {
return err
}
return nil
}
return errors.New("undefined response type")

return fmt.Errorf("unsupported response content-type: %s body: %s", contentType, string(b))
}

// Set request body from an interface{}
Expand Down
6 changes: 4 additions & 2 deletions templates/client/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -209,17 +208,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
if len(b) == 0 {
return nil
}

if s, ok := v.(*string); ok {
*s = string(b)
return nil
}

if jsonCheck.MatchString(contentType) {
if err = json.Unmarshal(b, v); err != nil {
return err
}
return nil
}
return errors.New("undefined response type")

return fmt.Errorf("unsupported response content-type: %s body: %s", contentType, string(b))
}

// Set request body from an interface{}
Expand Down

0 comments on commit 0605285

Please sign in to comment.