diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/persister.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/models/persister.go b/models/persister.go index 4381008..c6e0c72 100644 --- a/models/persister.go +++ b/models/persister.go @@ -82,14 +82,22 @@ func (p *Persister) Collect(model model) ([][]byte, error) { func (p *Persister) Find(model model) ([]byte, error) { var result []byte var item *badger.Item + var notFound bool err := p.db.View(func(txn *badger.Txn) error { var getErr error item, getErr = txn.Get([]byte(model.Key())) + if getErr == badger.ErrKeyNotFound { + notFound = true + return nil + } if getErr != nil { return getErr } return nil }) + if notFound { + return nil, nil // on key not found we want to return nil, so that gin returns 404 and not 500 + } if err != nil { return nil, err } |