diff options
author | 2023-03-06 09:38:43 +0000 | |
---|---|---|
committer | 2023-03-06 10:38:43 +0100 | |
commit | d8d5818b47009f28433a7e96bcce8d116c8a9769 (patch) | |
tree | a93b7fe7deaa286fde5eab450b4cb30fbe7566dd /internal/transport/dereference.go | |
parent | [feature] Add support for profile fields (#1483) (diff) | |
download | gotosocial-d8d5818b47009f28433a7e96bcce8d116c8a9769.tar.xz |
[bugfix] internal server error on search not found (#1590)
* add error value wrapping, include status code / not found flags from transport errors, update error usages
Signed-off-by: kim <grufwub@gmail.com>
* add code commenting for gtserror functions
Signed-off-by: kim <grufwub@gmail.com>
---------
Signed-off-by: kim <grufwub@gmail.com>
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) } |