From 5f72b04ef8e84b1c367ca6874519706318e351f5 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Fri, 19 Jun 2020 00:35:56 +0100 Subject: Use ErrNotAuthenticated --- graphql/resolvers/errors.go | 6 ------ graphql/resolvers/mutation.go | 12 ------------ graphql/resolvers/repo.go | 6 +++--- 3 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 graphql/resolvers/errors.go (limited to 'graphql/resolvers') diff --git a/graphql/resolvers/errors.go b/graphql/resolvers/errors.go deleted file mode 100644 index 2a8024e0..00000000 --- a/graphql/resolvers/errors.go +++ /dev/null @@ -1,6 +0,0 @@ -package resolvers - -import "errors" - -// ErrNotAuthenticated is returned to the client if the user requests an action requiring authentication, and they are not authenticated. -var ErrNotAuthenticated = errors.New("not authenticated or read-only") diff --git a/graphql/resolvers/mutation.go b/graphql/resolvers/mutation.go index 8d2d8081..31505047 100644 --- a/graphql/resolvers/mutation.go +++ b/graphql/resolvers/mutation.go @@ -47,8 +47,6 @@ func (r mutationResolver) NewBug(ctx context.Context, input models.NewBugInput) id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } b, op, err := repo.NewBugRaw(id, time.Now().Unix(), input.Title, input.Message, input.Files, nil) @@ -72,8 +70,6 @@ func (r mutationResolver) AddComment(ctx context.Context, input models.AddCommen id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } op, err := b.AddCommentRaw(id, time.Now().Unix(), input.Message, input.Files, nil) @@ -102,8 +98,6 @@ func (r mutationResolver) ChangeLabels(ctx context.Context, input *models.Change id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } results, op, err := b.ChangeLabelsRaw(id, time.Now().Unix(), input.Added, input.Removed, nil) @@ -138,8 +132,6 @@ func (r mutationResolver) OpenBug(ctx context.Context, input models.OpenBugInput id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } op, err := b.OpenRaw(id, time.Now().Unix(), nil) @@ -168,8 +160,6 @@ func (r mutationResolver) CloseBug(ctx context.Context, input models.CloseBugInp id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } op, err := b.CloseRaw(id, time.Now().Unix(), nil) @@ -198,8 +188,6 @@ func (r mutationResolver) SetTitle(ctx context.Context, input models.SetTitleInp id, err := graphqlidentity.ForContext(ctx, repo) if err != nil { return nil, err - } else if id == nil { - return nil, ErrNotAuthenticated } op, err := b.SetTitleRaw(id, time.Now().Unix(), input.Title, nil) diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go index f68ed3e0..009ccab6 100644 --- a/graphql/resolvers/repo.go +++ b/graphql/resolvers/repo.go @@ -152,10 +152,10 @@ func (repoResolver) Identity(_ context.Context, obj *models.Repository, prefix s func (repoResolver) UserIdentity(ctx context.Context, obj *models.Repository) (models.IdentityWrapper, error) { id, err := graphqlidentity.ForContext(ctx, obj.Repo) - if err != nil { - return nil, err - } else if id == nil { + if err == graphqlidentity.ErrNotAuthenticated { return nil, nil + } else if err != nil { + return nil, err } return models.NewLoadedIdentity(id.Identity), nil } -- cgit