Documentation ¶
Overview ¶
Package gqlerr provides helpers for handling errors that occur in a Go GraphQL server. It integrates logging via *zap.Logger so that all errors are logged. Codes are modeled after: https://pkg.go.dev/google.golang.org/grpc/codes
Index ¶
- func ErrorPresenter(logger *zap.Logger) func(context.Context, error) *gqlerror.Error
- func RecoverFunc(ctx context.Context, v any) error
- type Error
- func AlreadyExists(ctx context.Context, msg string, fields ...zap.Field) *Error
- func FailedPrecondition(ctx context.Context, msg string, fields ...zap.Field) *Error
- func Internal(ctx context.Context, msg string, fields ...zap.Field) *Error
- func InvalidArgument(ctx context.Context, msg string, fields ...zap.Field) *Error
- func New(ctx context.Context, code codes.Code, msg string, fields ...zap.Field) *Error
- func NotFound(ctx context.Context, msg string, fields ...zap.Field) *Error
- func PermissionDenied(ctx context.Context, msg string, fields ...zap.Field) *Error
- func ResourceExhausted(ctx context.Context, msg string, fields ...zap.Field) *Error
- func Unauthenticated(ctx context.Context, msg string, fields ...zap.Field) *Error
- func Unimplemented(ctx context.Context, msg string, fields ...zap.Field) *Error
- type ErrorID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorPresenter ¶
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func AlreadyExists ¶
func FailedPrecondition ¶
func InvalidArgument ¶
func New ¶
New returns an initialize error with the given code. The message and fields are used for logging, and won't be visible to clients. For setting client- visible response parameters, see WithErrorID and WithMessage
func PermissionDenied ¶
func ResourceExhausted ¶
func Unauthenticated ¶
func Unimplemented ¶
func (*Error) AtPanic ¶ added in v1.1.0
AtPanic overrides the default level for the error and logs at PANIC level. Note: This doesn't actually cause a panic when using a production zap logger, since we use DPanic.
func (*Error) WithErrorID ¶
WithErrorID adds an error intended for client apps to use, and returns the error for chaining purposes. It'll appear in the GraphQL response "extensions" field, see: https://spec.graphql.org/October2021/#sec-Response-Format
func (*Error) WithMessage ¶
WithMessage adds an error intended for clients to see, and returns the error for chaining purposes. It'll appear in the GraphQL response "errors" field, see: https://spec.graphql.org/October2021/#sec-Errors