Skip to content

Commit

Permalink
Added ErrNotFound to storage interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarvardt committed Jun 15, 2017
1 parent 9496ce7 commit a6391ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 11 additions & 1 deletion storage.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions storage_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package osin

import (
"errors"
"strconv"
"time"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit a6391ea

Please sign in to comment.