diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-02 13:07:21 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-02 13:07:21 +0000 |
commit | 8d23867d2c6d3c6f0dd9681192b9b8642ceea254 (patch) | |
tree | bb2a1609ebd188d2902fe9cf7d2590527e17c55b /models/persister.go | |
parent | 81873a1c6786b834a50486137f7b92b60e901d28 (diff) | |
download | communique-8d23867d2c6d3c6f0dd9681192b9b8642ceea254.tar.gz |
clean up error/response/not found handling
Diffstat (limited to '')
-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 } |