mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user