mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 22:16:15 -06:00
Use Tobi's style for wrapping errors
This commit is contained in:
parent
63ce52cbfa
commit
4f39da77bb
5 changed files with 20 additions and 26 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue