chore(http): return early if a critical error occurs in write path org/bucket lookup (#767)
parent
bbcbaee9fd
commit
43e0d143e7
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
|
@ -310,7 +309,7 @@ func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFi
|
|||
}
|
||||
|
||||
if n == 0 {
|
||||
return nil, errors.New("found no matching buckets")
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return bs[0], nil
|
||||
|
|
|
@ -16,6 +16,9 @@ const (
|
|||
errorHeaderMaxLength = 256
|
||||
)
|
||||
|
||||
// ErrNotFound is returned when a request for a resource returns no results.
|
||||
var ErrNotFound = errors.New("no results found")
|
||||
|
||||
// AuthzError is returned for authorization errors. When this error type is returned,
|
||||
// the user can be presented with a generic "authorization failed" error, but
|
||||
// the system can log the underlying AuthzError() so that operators have insight
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
|
@ -271,8 +270,8 @@ func (s *OrganizationService) FindOrganization(ctx context.Context, filter platf
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if n < 1 {
|
||||
return nil, errors.New("expected at least one organization")
|
||||
if n == 0 {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return os[0], nil
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
|
@ -294,7 +293,7 @@ func (s *UserService) FindUser(ctx context.Context, filter platform.UserFilter)
|
|||
}
|
||||
|
||||
if n == 0 {
|
||||
return nil, errors.New("found no matching user")
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return users[0], nil
|
||||
|
|
|
@ -78,8 +78,12 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
|
|||
var org *platform.Organization
|
||||
if id, err := platform.IDFromString(req.Org); err == nil {
|
||||
// Decoded ID successfully. Make sure it's a real org.
|
||||
if o, err := h.OrganizationService.FindOrganizationByID(ctx, *id); err == nil {
|
||||
o, err := h.OrganizationService.FindOrganizationByID(ctx, *id)
|
||||
if err == nil {
|
||||
org = o
|
||||
} else if err != ErrNotFound {
|
||||
EncodeError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
}
|
||||
if org == nil {
|
||||
|
@ -96,11 +100,15 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
|
|||
var bucket *platform.Bucket
|
||||
if id, err := platform.IDFromString(req.Bucket); err == nil {
|
||||
// Decoded ID successfully. Make sure it's a real bucket.
|
||||
if b, err := h.BucketService.FindBucket(ctx, platform.BucketFilter{
|
||||
b, err := h.BucketService.FindBucket(ctx, platform.BucketFilter{
|
||||
OrganizationID: &org.ID,
|
||||
ID: id,
|
||||
}); err == nil {
|
||||
})
|
||||
if err == nil {
|
||||
bucket = b
|
||||
} else if err != ErrNotFound {
|
||||
EncodeError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue