diff --git a/internal/processing/push/create.go b/internal/processing/push/create.go index 8da2a1cf5..42a67dc19 100644 --- a/internal/processing/push/create.go +++ b/internal/processing/push/create.go @@ -41,9 +41,8 @@ func (p *Processor) CreateOrReplace( // Clear any previous subscription. if err := p.state.DB.DeleteWebPushSubscriptionByTokenID(ctx, tokenID); err != nil { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("couldn't delete Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't delete Web Push subscription for token ID %s: %w", tokenID, err) + return nil, gtserror.NewErrorInternalError(err) } // Insert a new one. @@ -58,9 +57,8 @@ func (p *Processor) CreateOrReplace( } if err := p.state.DB.PutWebPushSubscription(ctx, subscription); err != nil { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("couldn't create Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't create Web Push subscription for token ID %s: %w", tokenID, err) + return nil, gtserror.NewErrorInternalError(err) } return p.apiSubscription(ctx, subscription) diff --git a/internal/processing/push/delete.go b/internal/processing/push/delete.go index 48d25a42f..6f5c61444 100644 --- a/internal/processing/push/delete.go +++ b/internal/processing/push/delete.go @@ -31,9 +31,8 @@ func (p *Processor) Delete(ctx context.Context, accessToken string) gtserror.Wit } if err := p.state.DB.DeleteWebPushSubscriptionByTokenID(ctx, tokenID); err != nil { - return gtserror.NewErrorInternalError( - gtserror.Newf("couldn't delete Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't delete Web Push subscription for token ID %s: %w", tokenID, err) + return gtserror.NewErrorInternalError(err) } return nil diff --git a/internal/processing/push/get.go b/internal/processing/push/get.go index 2f19ae223..542f08862 100644 --- a/internal/processing/push/get.go +++ b/internal/processing/push/get.go @@ -35,12 +35,12 @@ func (p *Processor) Get(ctx context.Context, accessToken string) (*apimodel.WebP subscription, err := p.state.DB.GetWebPushSubscriptionByTokenID(ctx, tokenID) if err != nil && !errors.Is(err, db.ErrNoEntries) { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("couldn't get Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't get Web Push subscription for token ID %s: %w", tokenID, err) + return nil, gtserror.NewErrorInternalError(err) } if subscription == nil { - return nil, gtserror.NewErrorNotFound(errors.New("no Web Push subscription exists for this access token")) + err := errors.New("no Web Push subscription exists for this access token") + return nil, gtserror.NewErrorNotFound(err) } return p.apiSubscription(ctx, subscription) diff --git a/internal/processing/push/push.go b/internal/processing/push/push.go index 7635229fa..f46280386 100644 --- a/internal/processing/push/push.go +++ b/internal/processing/push/push.go @@ -44,9 +44,8 @@ func New(state *state.State, converter *typeutils.Converter) Processor { func (p *Processor) getTokenID(ctx context.Context, accessToken string) (string, gtserror.WithCode) { token, err := p.state.DB.GetTokenByAccess(ctx, accessToken) if err != nil { - return "", gtserror.NewErrorInternalError( - gtserror.Newf("couldn't find token ID for access token: %w", err), - ) + err := gtserror.Newf("couldn't find token ID for access token: %w", err) + return "", gtserror.NewErrorInternalError(err) } return token.ID, nil @@ -57,9 +56,8 @@ func (p *Processor) getTokenID(ctx context.Context, accessToken string) (string, func (p *Processor) apiSubscription(ctx context.Context, subscription *gtsmodel.WebPushSubscription) (*apimodel.WebPushSubscription, gtserror.WithCode) { apiSubscription, err := p.converter.WebPushSubscriptionToAPIWebPushSubscription(ctx, subscription) if err != nil { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("error converting Web Push subscription %s to API representation: %w", subscription.ID, err), - ) + err := gtserror.Newf("error converting Web Push subscription %s to API representation: %w", subscription.ID, err) + return nil, gtserror.NewErrorInternalError(err) } return apiSubscription, nil diff --git a/internal/processing/push/update.go b/internal/processing/push/update.go index bd0dec494..370536f9b 100644 --- a/internal/processing/push/update.go +++ b/internal/processing/push/update.go @@ -40,12 +40,12 @@ func (p *Processor) Update( // Get existing subscription. subscription, err := p.state.DB.GetWebPushSubscriptionByTokenID(ctx, tokenID) if err != nil && !errors.Is(err, db.ErrNoEntries) { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("couldn't get Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't get Web Push subscription for token ID %s: %w", tokenID, err) + return nil, gtserror.NewErrorInternalError(err) } if subscription == nil { - return nil, gtserror.NewErrorNotFound(errors.New("no Web Push subscription exists for this access token")) + err := errors.New("no Web Push subscription exists for this access token") + return nil, gtserror.NewErrorNotFound(err) } // Update it. @@ -55,9 +55,8 @@ func (p *Processor) Update( subscription, "notification_flags", ); err != nil { - return nil, gtserror.NewErrorInternalError( - gtserror.Newf("couldn't update Web Push subscription for token ID %s: %w", tokenID, err), - ) + err := gtserror.Newf("couldn't update Web Push subscription for token ID %s: %w", tokenID, err) + return nil, gtserror.NewErrorInternalError(err) } return p.apiSubscription(ctx, subscription)