diff options
Diffstat (limited to 'internal/transport/dereference.go')
-rw-r--r-- | internal/transport/dereference.go | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/internal/transport/dereference.go b/internal/transport/dereference.go index f42f146ea..d82a1ac8a 100644 --- a/internal/transport/dereference.go +++ b/internal/transport/dereference.go @@ -20,7 +20,6 @@ package transport import ( "context" - "errors" "fmt" "io" "net/http" @@ -28,15 +27,10 @@ import ( apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/uris" ) -// ErrGone is returned from Dereference when the remote resource returns 410 GONE. -// This is useful in cases where we're processing a delete of a resource that's already -// been removed from the remote server, so we know we don't need to keep trying to -// dereference it. -var ErrGone = errors.New("remote resource returned HTTP code 410 GONE") - func (t *transport) Dereference(ctx context.Context, iri *url.URL) ([]byte, error) { // if the request is to us, we can shortcut for certain URIs rather than going through // the normal request flow, thereby saving time and energy @@ -72,12 +66,10 @@ func (t *transport) Dereference(ctx context.Context, iri *url.URL) ([]byte, erro } defer rsp.Body.Close() - switch rsp.StatusCode { - case http.StatusOK: - return io.ReadAll(rsp.Body) - case http.StatusGone: - return nil, ErrGone - default: - return nil, fmt.Errorf("GET request to %s failed: %s", iriStr, rsp.Status) + if rsp.StatusCode != http.StatusOK { + err := fmt.Errorf("GET request to %s failed: %s", iriStr, rsp.Status) + return nil, gtserror.WithStatusCode(err, rsp.StatusCode) } + + return io.ReadAll(rsp.Body) } |