Skip to content

Commit

Permalink
If the graphql.AddError err arg is nil, early return
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed Dec 20, 2024
1 parent b95ea13 commit 888df00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions graphql/context_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func AddErrorf(ctx context.Context, format string, args ...any) {

// AddError sends an error to the client, first passing it through the error presenter.
func AddError(ctx context.Context, err error) {
if err == nil {
return
}
c := getResponseContext(ctx)

presentedError := c.errorPresenter(ctx, ErrorOnPath(ctx, err))
Expand Down
3 changes: 3 additions & 0 deletions graphql/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
type ErrorPresenterFunc func(ctx context.Context, err error) *gqlerror.Error

func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error {
if err == nil {
return nil
}
var gqlErr *gqlerror.Error
if errors.As(err, &gqlErr) {
return gqlErr
Expand Down

0 comments on commit 888df00

Please sign in to comment.