core/txfeed: fix not-found status code for Find() #531

Merged
merged 2 commits into from Feb 15, 2017

Projects

None yet

3 participants

@jeffomatic
Member

When retrieving a transaction feed by alias, an empty response
should return a CH002 error, rather than a CH000. This is resolved
by substituting sql.ErrNoRows with pg.ErrUserInputNotFound.

@jeffomatic jeffomatic added the PTAL label Feb 15, 2017
@jeffomatic
Member

PTAL

core/txfeed/txfeed.go
@@ -130,6 +130,9 @@ func (t *Tracker) Find(ctx context.Context, id, alias string) (*TxFeed, error) {
)
err := t.DB.QueryRow(ctx, q.String(), id).Scan(&feed.ID, &sqlAlias, &feed.Filter, &feed.After)
+ if err == sql.ErrNoRows {
+ return nil, errors.WithDetailf(pg.ErrUserInputNotFound, "alias: %s", alias)
@kr
kr Feb 15, 2017 Member

We have a new function! https://godoc.org/github.com/chain/chain/errors#Sub

I suggest:

err = errors.Sub(pg.ErrUserInputNotFound, err)
err = errors.WithDetailf(err, "alias: %s", alias)
return nil, err

This way if err already has a stack trace or detail or whatever, they'll all be preserved.

@jeffomatic
Member

added call to errors.Sub, PTAL

@kr
kr approved these changes Feb 15, 2017 View changes
@kr
Member
kr commented Feb 15, 2017

LGTM

jeffomatic added some commits Feb 15, 2017
@jeffomatic @chainbot jeffomatic core/txfeed: fix not-found status code for Find()
When retrieving a transaction feed by alias, an empty response
should return a CH002 error, rather than a CH000. This is resolved
by substituting sql.ErrNoRows with pg.ErrUserInputNotFound.
1a82661
@jeffomatic @chainbot jeffomatic use Sub idiom
1eebd69
@chainbot chainbot merged commit 27b0fc5 into main Feb 15, 2017

3 checks passed

licence/cla Contributor License Agreement is signed.
Details
wercker/cored Wercker pipeline passed
Details
wercker/java Wercker pipeline passed
Details
@chainbot chainbot deleted the quiet-confidence branch Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment