From 32f482812bf9c3688bfc1c2df423db8a4777f34c Mon Sep 17 00:00:00 2001 From: Conrad Hoffmann Date: Tue, 14 Apr 2026 11:39:01 +0200 Subject: [PATCH] errors: add ERR_REDIRECT This error is meant to be returned if a resource is requested that does not exist under the requested name anymore but was moved to a different resource. --- errors/errors.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/errors/errors.go b/errors/errors.go index 0da300acf420d24ff7185ef35eb7ba5ac62d7f3a..c5885d6991fe0334cd0b1e131977c87bb2d65c48 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -25,6 +25,19 @@ func Errorf(code ErrorCode, format string, a ...any) *gqlerror.Error { } } +// Creates a new "redirect" GraphQL error pointing to the provided path. The +// path should be broken down into path segments. The length of the path is +// dependent on the type of resource being requested. +func RedirectTo(path []string) *gqlerror.Error { + return &gqlerror.Error{ + Message: "The requested resource was moved", + Extensions: map[string]any{ + "code": Redirect, + "redirect": path, + }, + } +} + // Sets the field name that caused the error func Field(err *gqlerror.Error, field string) *gqlerror.Error { err.Extensions["field"] = field @@ -57,6 +70,7 @@ var ( Unauthorized ErrorCode = "ERR_UNAUTHORIZED" InternalError ErrorCode = "ERR_INTERNAL" Timeout ErrorCode = "ERR_TIMEOUT" + Redirect ErrorCode = "ERR_REDIRECT" ) // Error codes as Go errors @@ -67,4 +81,5 @@ var ( ErrUnauthorized = New(Unauthorized, "Unauthorized") ErrInternalError = New(InternalError, "Internal server error") ErrTimeout = New(Timeout, "Operation timed out") + ErrRedirect = New(Redirect, "The requested resource was moved") )