mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 14:39:14 -06: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:
parent
f518f649f8
commit
d8d5818b47
9 changed files with 108 additions and 37 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"encoding/pem"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
|
@ -226,7 +227,7 @@ func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedU
|
|||
// The actual http call to the remote server is made right here in the Dereference function.
|
||||
b, err := trans.Dereference(ctx, requestingPublicKeyID)
|
||||
if err != nil {
|
||||
if errors.Is(err, transport.ErrGone) {
|
||||
if gtserror.StatusCode(err) == http.StatusGone {
|
||||
// if we get a 410 error it means the account that owns this public key has been deleted;
|
||||
// we should add a tombstone to our database so that we can avoid trying to deref it in future
|
||||
if err := f.HandleGone(ctx, requestingPublicKeyID); err != nil {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
package dereferencing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
)
|
||||
|
||||
// ErrDB denotes that a proper error has occurred when doing
|
||||
|
|
@ -96,22 +96,21 @@ func newErrOther(err error) error {
|
|||
}
|
||||
|
||||
func wrapDerefError(derefErr error, fluff string) error {
|
||||
var (
|
||||
err error
|
||||
errWrongType *ErrWrongType
|
||||
)
|
||||
|
||||
// Wrap with fluff.
|
||||
err := derefErr
|
||||
if fluff != "" {
|
||||
err = fmt.Errorf("%s: %w", fluff, derefErr)
|
||||
}
|
||||
|
||||
switch {
|
||||
case errors.Is(derefErr, transport.ErrGone):
|
||||
err = NewErrNotRetrievable(err)
|
||||
case errors.As(derefErr, &errWrongType):
|
||||
err = newErrWrongType(err)
|
||||
default:
|
||||
err = newErrTransportError(err)
|
||||
// Check for unretrievable HTTP status code errors.
|
||||
if code := gtserror.StatusCode(derefErr); // nocollapse
|
||||
code == http.StatusGone || code == http.StatusNotFound {
|
||||
return NewErrNotRetrievable(err)
|
||||
}
|
||||
|
||||
// Check for other untrievable errors.
|
||||
if gtserror.NotFound(derefErr) {
|
||||
return NewErrNotRetrievable(err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
||||
|
|
@ -210,7 +211,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
|
|||
transport.WithFastfail(ctx), username, publicKeyOwnerURI, false,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, transport.ErrGone) {
|
||||
if gtserror.StatusCode(err) == http.StatusGone {
|
||||
// This is the same case as the http.StatusGone check above.
|
||||
// It can happen here and not there because there's a race
|
||||
// where the sending server starts sending account deletion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue