Skip to content

Commit a6391ea

Browse files
committed
Added ErrNotFound to storage interface
1 parent 9496ce7 commit a6391ea

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

storage.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
package osin
22

3-
import ()
3+
import (
4+
"errors"
5+
)
6+
7+
var (
8+
// ErrNotFound is the error returned by Storage Get<...> and Load<...> functions in case
9+
// no entity is found in the storage. E.g. Storage.GetClient() returns ErrNotFound when
10+
// client is not found. All other returned errors must be treated as storage-specific errors,
11+
// like "connection lost", "connection refused", etc.
12+
ErrNotFound = errors.New("Entity not found")
13+
)
414

515
// Storage interface
616
type Storage interface {

storage_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package osin
22

33
import (
4-
"errors"
54
"strconv"
65
"time"
76
)
@@ -74,7 +73,7 @@ func (s *TestingStorage) GetClient(id string) (Client, error) {
7473
if c, ok := s.clients[id]; ok {
7574
return c, nil
7675
}
77-
return nil, errors.New("Client not found")
76+
return nil, ErrNotFound
7877
}
7978

8079
func (s *TestingStorage) SetClient(id string, client Client) error {
@@ -91,7 +90,7 @@ func (s *TestingStorage) LoadAuthorize(code string) (*AuthorizeData, error) {
9190
if d, ok := s.authorize[code]; ok {
9291
return d, nil
9392
}
94-
return nil, errors.New("Authorize not found")
93+
return nil, ErrNotFound
9594
}
9695

9796
func (s *TestingStorage) RemoveAuthorize(code string) error {
@@ -111,7 +110,7 @@ func (s *TestingStorage) LoadAccess(code string) (*AccessData, error) {
111110
if d, ok := s.access[code]; ok {
112111
return d, nil
113112
}
114-
return nil, errors.New("Access not found")
113+
return nil, ErrNotFound
115114
}
116115

117116
func (s *TestingStorage) RemoveAccess(code string) error {
@@ -123,7 +122,7 @@ func (s *TestingStorage) LoadRefresh(code string) (*AccessData, error) {
123122
if d, ok := s.refresh[code]; ok {
124123
return s.LoadAccess(d)
125124
}
126-
return nil, errors.New("Refresh not found")
125+
return nil, ErrNotFound
127126
}
128127

129128
func (s *TestingStorage) RemoveRefresh(code string) error {

0 commit comments

Comments
 (0)