summaryrefslogtreecommitdiff
path: root/internal/processing/account/update.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-06-08 20:38:03 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-08 20:38:03 +0200
commit1ede54ddf6dfd2d4ba039eb7e23b74bcac65b643 (patch)
tree727436fb9bf9da25e30c5ded65c5b5ccaffe0cf0 /internal/processing/account/update.go
parent[bugfix] #621: add weak type handing to mapstructure decode (#625) (diff)
downloadgotosocial-1ede54ddf6dfd2d4ba039eb7e23b74bcac65b643.tar.xz
[feature] More consistent API error handling (#637)
* update templates * start reworking api error handling * update template * return AP status at web endpoint if negotiated * start making api error handling much more consistent * update account endpoints to new error handling * use new api error handling in admin endpoints * go fmt ./... * use api error logic in app * use generic error handling in auth * don't export generic error handler * don't defer clearing session * user nicer error handling on oidc callback handler * tidy up the sign in handler * tidy up the token handler * use nicer error handling in blocksget * auth emojis endpoint * fix up remaining api endpoints * fix whoopsie during login flow * regenerate swagger docs * change http error logging to debug
Diffstat (limited to 'internal/processing/account/update.go')
-rw-r--r--internal/processing/account/update.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 42da40ffe..d1085845b 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -29,6 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -37,7 +38,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/validate"
)
-func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, error) {
+func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, gtserror.WithCode) {
l := logrus.WithField("func", "AccountUpdate")
if form.Discoverable != nil {
@@ -50,14 +51,14 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.DisplayName != nil {
if err := validate.DisplayName(*form.DisplayName); err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
account.DisplayName = text.SanitizePlaintext(*form.DisplayName)
}
if form.Note != nil {
if err := validate.Note(*form.Note); err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
// Set the raw note before processing
@@ -66,7 +67,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// Process note to generate a valid HTML representation
note, err := p.processNote(ctx, *form.Note, account.ID)
if err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
// Set updated HTML-ified note
@@ -76,7 +77,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.Avatar != nil && form.Avatar.Size != 0 {
avatarInfo, err := p.UpdateAvatar(ctx, form.Avatar, account.ID)
if err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
account.AvatarMediaAttachmentID = avatarInfo.ID
account.AvatarMediaAttachment = avatarInfo
@@ -86,7 +87,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.Header != nil && form.Header.Size != 0 {
headerInfo, err := p.UpdateHeader(ctx, form.Header, account.ID)
if err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
account.HeaderMediaAttachmentID = headerInfo.ID
account.HeaderMediaAttachment = headerInfo
@@ -100,7 +101,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.Source != nil {
if form.Source.Language != nil {
if err := validate.Language(*form.Source.Language); err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
account.Language = *form.Source.Language
}
@@ -111,7 +112,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
if form.Source.Privacy != nil {
if err := validate.Privacy(*form.Source.Privacy); err != nil {
- return nil, err
+ return nil, gtserror.NewErrorBadRequest(err)
}
privacy := p.tc.APIVisToVis(apimodel.Visibility(*form.Source.Privacy))
account.Privacy = privacy
@@ -120,7 +121,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
updatedAccount, err := p.db.UpdateAccount(ctx, account)
if err != nil {
- return nil, fmt.Errorf("could not update account %s: %s", account.ID, err)
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not update account %s: %s", account.ID, err))
}
p.clientWorker.Queue(messages.FromClientAPI{
@@ -132,7 +133,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
acctSensitive, err := p.tc.AccountToAPIAccountSensitive(ctx, updatedAccount)
if err != nil {
- return nil, fmt.Errorf("could not convert account into apisensitive account: %s", err)
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not convert account into apisensitive account: %s", err))
}
return acctSensitive, nil
}