diff --git a/errors/errors.go b/errors/errors.go index 05a450f44ccd672e40fd0d0900c85fb8f9c83b7b..b373c95fb5f9a968459cc61f68cd345b78404eb6 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -37,6 +37,7 @@ NotFound ErrorCode = "ERR_NOT_FOUND" Unsupported ErrorCode = "ERR_UNSUPPORTED" Unauthorized ErrorCode = "ERR_UNAUTHORIZED" InternalError ErrorCode = "ERR_INTERNAL" + Timeout ErrorCode = "ERR_TIMEOUT" ) // Error codes as Go errors @@ -46,4 +47,5 @@ ErrNotFound = New(NotFound, "Resource not found") ErrUnsupported = New(Unsupported, "Not supported") ErrUnauthorized = New(Unauthorized, "Unauthorized") ErrInternalError = New(InternalError, "Internal server error") + ErrTimeout = New(Timeout, "Operation timed out") ) diff --git a/server/server.go b/server/server.go index 18987318ab71e4527c85e0281bfa5f69ac8cd2ac..5f313d19722e4a291dc5c34680326ff39904a51d 100644 --- a/server/server.go +++ b/server/server.go @@ -5,6 +5,7 @@ "context" "database/sql" "encoding/base64" "encoding/json" + "errors" "fmt" "log" "net" @@ -33,12 +34,14 @@ "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/vaughan0/go-ini" + "github.com/vektah/gqlparser/v2/gqlerror" "git.sr.ht/~sircmpwn/core-go/auth" "git.sr.ht/~sircmpwn/core-go/config" "git.sr.ht/~sircmpwn/core-go/crypto" "git.sr.ht/~sircmpwn/core-go/database" "git.sr.ht/~sircmpwn/core-go/email" + coreerrors "git.sr.ht/~sircmpwn/core-go/errors" "git.sr.ht/~sircmpwn/core-go/feature" "git.sr.ht/~sircmpwn/core-go/redis" ) @@ -145,6 +148,12 @@ srv.AddTransport(transport.POST{}) srv.AddTransport(transport.MultipartForm{ MaxMemory: 33554432, // 32 MiB (up to this handled in memory) MaxUploadSize: 1073741824, // 1 GiB (TODO: configurable?) + }) + srv.SetErrorPresenter(func(ctx context.Context, err error) *gqlerror.Error { + if errors.Is(err, context.DeadlineExceeded) { + return coreerrors.ErrTimeout + } + return graphql.DefaultErrorPresenter(ctx, err) }) if debug {