mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
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:
39
internal/api/error.go
Normal file
39
internal/api/error.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user