Log errors returned from graphql (#3562)

* Add func methods to logger
* Log errors returned from the graphql interface
* Log authentication
* Log when credentials changed
This commit is contained in:
WithoutPants
2023-04-17 15:27:25 +10:00
committed by GitHub
parent 75f22042b7
commit 32cefea524
8 changed files with 177 additions and 4 deletions

39
internal/api/error.go Normal file
View File

@@ -0,0 +1,39 @@
package api
import (
"context"
"encoding/json"
"github.com/99designs/gqlgen/graphql"
"github.com/stashapp/stash/pkg/logger"
"github.com/vektah/gqlparser/v2/gqlerror"
)
func gqlErrorHandler(ctx context.Context, e error) *gqlerror.Error {
// log all errors - for now just log the error message
// we can potentially add more context later
fc := graphql.GetFieldContext(ctx)
if fc != nil {
logger.Errorf("%s: %v", fc.Path(), e)
// log the args in debug level
logger.DebugFunc(func() (string, []interface{}) {
var args interface{}
args = fc.Args
s, _ := json.Marshal(args)
if len(s) > 0 {
args = string(s)
}
return "%s: %v", []interface{}{
fc.Path(),
args,
}
})
}
// we may also want to transform the error message for the response
// for now just return the original error
return graphql.DefaultErrorPresenter(ctx, e)
}