summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/authenticate.go3
-rw-r--r--internal/federation/dereferencing/error.go27
-rw-r--r--internal/federation/federatingprotocol.go3
3 files changed, 17 insertions, 16 deletions
diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go
index a966bb26a..32e427542 100644
--- a/internal/federation/authenticate.go
+++ b/internal/federation/authenticate.go
@@ -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 {
diff --git a/internal/federation/dereferencing/error.go b/internal/federation/dereferencing/error.go
index 3ba357f7a..530c72b32 100644
--- a/internal/federation/dereferencing/error.go
+++ b/internal/federation/dereferencing/error.go
@@ -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
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index e60f278c7..49b38eda4 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -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