Skip to content

Commit

Permalink
[chore] Refactor federatingDB.Undo, avoid 500 errors on Undo Like (#3310
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tsmethurst authored Sep 16, 2024
1 parent 71261c6 commit 0567b31
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 90 deletions.
26 changes: 17 additions & 9 deletions internal/federation/federatingactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,32 @@ func (f *federatingActor) PostInboxScheme(ctx context.Context, w http.ResponseWr
// the POST request is authentic (properly signed) and authorized
// (permitted to interact with the target inbox).
//
// Post the activity to the Actor's inbox and trigger side effects .
// Post the activity to the Actor's inbox and trigger side effects.
if err := f.sideEffectActor.PostInbox(ctx, inboxID, activity); err != nil {
// Special case: We know it is a bad request if the object or target
// props needed to be populated, or we failed parsing activity details.
// Send the rejection to the peer.
if errors.Is(err, pub.ErrObjectRequired) ||
errors.Is(err, pub.ErrTargetRequired) ||
gtserror.IsMalformed(err) {
// Check if a function in the federatingDB
// has returned an explicit errWithCode for us.
if errWithCode, ok := err.(gtserror.WithCode); ok {
return false, errWithCode
}

// Check if it's a bad request because the
// object or target props weren't populated,
// or we failed parsing activity details.
//
// Log such activities to help debug, then
// return the rejection (400) to the peer.
if gtserror.IsMalformed(err) ||
errors.Is(err, pub.ErrObjectRequired) ||
errors.Is(err, pub.ErrTargetRequired) {

// Log malformed activities to help debug.
l = l.WithField("activity", activity)
l.Warnf("malformed incoming activity: %v", err)

const text = "malformed incoming activity"
return false, gtserror.NewErrorBadRequest(errors.New(text), text)
}

// There's been some real error.
// Default: there's been some real error.
err := gtserror.Newf("error calling sideEffectActor.PostInbox: %w", err)
return false, gtserror.NewErrorInternalError(err)
}
Expand Down
Loading

0 comments on commit 0567b31

Please sign in to comment.