diff --git a/example/teststorage.go b/example/teststorage.go index 0b59275..17001fe 100644 --- a/example/teststorage.go +++ b/example/teststorage.go @@ -1,7 +1,6 @@ package example import ( - "errors" "fmt" "github.com/RangelReale/osin" ) @@ -42,7 +41,7 @@ func (s *TestStorage) GetClient(id string) (osin.Client, error) { if c, ok := s.clients[id]; ok { return c, nil } - return nil, errors.New("Client not found") + return nil, osin.ErrNotFound } func (s *TestStorage) SetClient(id string, client osin.Client) error { @@ -62,7 +61,7 @@ func (s *TestStorage) LoadAuthorize(code string) (*osin.AuthorizeData, error) { if d, ok := s.authorize[code]; ok { return d, nil } - return nil, errors.New("Authorize not found") + return nil, osin.ErrNotFound } func (s *TestStorage) RemoveAuthorize(code string) error { @@ -85,7 +84,7 @@ func (s *TestStorage) LoadAccess(code string) (*osin.AccessData, error) { if d, ok := s.access[code]; ok { return d, nil } - return nil, errors.New("Access not found") + return nil, osin.ErrNotFound } func (s *TestStorage) RemoveAccess(code string) error { @@ -99,7 +98,7 @@ func (s *TestStorage) LoadRefresh(code string) (*osin.AccessData, error) { if d, ok := s.refresh[code]; ok { return s.LoadAccess(d) } - return nil, errors.New("Refresh not found") + return nil, osin.ErrNotFound } func (s *TestStorage) RemoveRefresh(code string) error { diff --git a/storage.go b/storage.go index d3dea96..425fc36 100644 --- a/storage.go +++ b/storage.go @@ -1,6 +1,16 @@ package osin -import () +import ( + "errors" +) + +var ( + // ErrNotFound is the error returned by Storage Get<...> and Load<...> functions in case + // no entity is found in the storage. E.g. Storage.GetClient() returns ErrNotFound when + // client is not found. All other returned errors must be treated as storage-specific errors, + // like "connection lost", "connection refused", etc. + ErrNotFound = errors.New("Entity not found") +) // Storage interface type Storage interface { diff --git a/storage_test.go b/storage_test.go index ce2a3d7..639d23a 100644 --- a/storage_test.go +++ b/storage_test.go @@ -1,7 +1,6 @@ package osin import ( - "errors" "strconv" "time" ) @@ -74,7 +73,7 @@ func (s *TestingStorage) GetClient(id string) (Client, error) { if c, ok := s.clients[id]; ok { return c, nil } - return nil, errors.New("Client not found") + return nil, ErrNotFound } func (s *TestingStorage) SetClient(id string, client Client) error { @@ -91,7 +90,7 @@ func (s *TestingStorage) LoadAuthorize(code string) (*AuthorizeData, error) { if d, ok := s.authorize[code]; ok { return d, nil } - return nil, errors.New("Authorize not found") + return nil, ErrNotFound } func (s *TestingStorage) RemoveAuthorize(code string) error { @@ -111,7 +110,7 @@ func (s *TestingStorage) LoadAccess(code string) (*AccessData, error) { if d, ok := s.access[code]; ok { return d, nil } - return nil, errors.New("Access not found") + return nil, ErrNotFound } func (s *TestingStorage) RemoveAccess(code string) error { @@ -123,7 +122,7 @@ func (s *TestingStorage) LoadRefresh(code string) (*AccessData, error) { if d, ok := s.refresh[code]; ok { return s.LoadAccess(d) } - return nil, errors.New("Refresh not found") + return nil, ErrNotFound } func (s *TestingStorage) RemoveRefresh(code string) error {