Merge pull request #3 from FlipsideCrypto/error-handling

wrap errors to get stack trace
This commit is contained in:
Don Cote 2019-09-13 14:29:57 -04:00 committed by GitHub
commit 90a3549304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/FlipsideCrypto/go-data-bridge-client
go 1.12
require (
github.com/pkg/errors v0.8.1
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect

2
go.sum
View File

@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -5,6 +5,8 @@ import (
"fmt"
"io/ioutil"
"net/http"
"github.com/pkg/errors"
)
// Record represents a Data Bridge data record
@ -22,7 +24,7 @@ func getNextRecord(c Client) (*Record, error) {
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
return nil, errors.Wrap(err, fmt.Sprintf("error making databridge http request for %s", url))
}
if res.StatusCode == 404 {
@ -32,13 +34,13 @@ func getNextRecord(c Client) (*Record, error) {
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "error trying to read databridge response body")
}
var record Record
err = json.Unmarshal([]byte(body), &record)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "error trying to unmarshal response body to json")
}
return &record, nil
@ -53,7 +55,7 @@ func (r Record) updateRecordState(c Client, state string) error {
_, err := http.DefaultClient.Do(req)
if err != nil {
return err
return errors.Wrap(err, fmt.Sprintf("error attempting to update databridge record state for %s", url))
}
// todo - probably get more granular on checking this response