return nil/nil on 404

This commit is contained in:
Don Cote 2019-07-17 13:26:23 -04:00
parent 5a0e58ab63
commit d4920637e1
2 changed files with 10 additions and 0 deletions

View File

@ -1,11 +1,13 @@
package databridge
// Config allows a consuming app to set up API Key, Consumer ID, and Topic Slug
type Config struct {
APIKey string
ConsumerID string
TopicSlug string
}
// Client allows access to the Databridge API
type Client struct {
BaseURL string
APIKey string
@ -13,6 +15,7 @@ type Client struct {
ConsumerID string
}
// NewClient returns a new Databridge Client
func NewClient(config Config) (Client, error) {
c := Client{}
c.APIKey = config.APIKey
@ -23,14 +26,17 @@ func NewClient(config Config) (Client, error) {
return c, nil
}
// GetNextRecord returns the topic's next record. Will return nil without an error when there are no more records.
func (c Client) GetNextRecord() (*Record, error) {
return getNextRecord(c)
}
// CompleteRecord allows the record to be marked as completed
func (c Client) CompleteRecord(r Record) error {
return r.updateRecordState(c, "completed")
}
// FailRecord allows the record to be marked as failed
func (c Client) FailRecord(r Record) error {
return r.updateRecordState(c, "failed")
}

View File

@ -25,6 +25,10 @@ func getNextRecord(c Client) (*Record, error) {
return nil, err
}
if res.StatusCode == 404 {
return nil, nil
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {