Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer9 committed Mar 20, 2018
1 parent 4794114 commit 3df5a53
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpc
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"path"
Expand Down Expand Up @@ -144,17 +145,15 @@ func (r OpenBazaarRPC) GetUserAgent(id string) (string, error) {
return "", err
}
responseRaw := new(bytes.Buffer)
responseRaw.ReadFrom(resp.Body)

response := responseRaw.String()

if err := json.Unmarshal(responseRaw.Bytes(), &response); err != nil {
fmt.Println(err)
var possibleError ErrorResponse
if err := json.Unmarshal(responseRaw.Bytes(), &possibleError); err == nil {
return "", nil // fail silently
}
_, err = responseRaw.ReadFrom(resp.Body)
if err != nil {
return "", err
}
return response, nil

var possibleError ErrorResponse
if err := json.Unmarshal(responseRaw.Bytes(), &possibleError); err == nil {
return "", errors.New(possibleError.Reason)
}

return responseRaw.String(), nil
}

0 comments on commit 3df5a53

Please sign in to comment.