replace repeated text with error func

This commit is contained in:
tobi 2024-03-13 13:22:09 +01:00
parent f899017b68
commit 322d3c5ffb
36 changed files with 57 additions and 85 deletions

View file

@ -98,8 +98,7 @@ func (m *Module) AccountFollowPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package accounts
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@ -76,8 +75,7 @@ func (m *Module) AccountLookupGETHandler(c *gin.Context) {
if authed.Account.IsMoving() {
// For moving/moved accounts, just return
// empty to avoid breaking client apps.
const text = "no results"
apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.NotFoundAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package accounts
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@ -83,8 +82,7 @@ func (m *Module) AccountNotePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -100,8 +100,7 @@ func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -108,8 +108,7 @@ func (m *Module) DomainKeysExpirePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -76,8 +76,7 @@ func (m *Module) createDomainPermissions(
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}
@ -185,8 +184,7 @@ func (m *Module) deleteDomainPermission(
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package admin
import (
"errors"
"fmt"
"net/http"
"net/mail"
@ -95,8 +94,7 @@ func (m *Module) EmailTestPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -111,8 +111,7 @@ func (m *Module) EmojiCreatePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -88,8 +88,7 @@ func (m *Module) EmojiDELETEHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -138,8 +138,7 @@ func (m *Module) EmojiPATCHHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -115,8 +115,7 @@ func (m *Module) createHeaderFilter(c *gin.Context, create func(context.Context,
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}
@ -164,8 +163,7 @@ func (m *Module) deleteHeaderFilter(c *gin.Context, delete func(context.Context,
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package admin
import (
"errors"
"fmt"
"net/http"
@ -83,8 +82,7 @@ func (m *Module) MediaCleanupPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package admin
import (
"errors"
"fmt"
"net/http"
@ -85,8 +84,7 @@ func (m *Module) MediaRefetchPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -98,8 +98,7 @@ func (m *Module) ReportResolvePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -78,8 +78,7 @@ func (m *Module) RulePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -86,8 +86,7 @@ func (m *Module) RuleDELETEHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -78,8 +78,7 @@ func (m *Module) RulePATCHHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package v1
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@ -133,8 +132,7 @@ func (m *Module) FilterPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package v1
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@ -139,8 +138,7 @@ func (m *Module) FilterPUTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -76,8 +76,7 @@ func (m *Module) FollowRequestAuthorizePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -145,8 +145,7 @@ func (m *Module) InstanceUpdatePATCHHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -88,8 +88,7 @@ func (m *Module) ListAccountsPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package lists
import (
"errors"
"net/http"
"strings"
@ -76,8 +75,7 @@ func (m *Module) ListCreatePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -105,8 +105,7 @@ func (m *Module) ListUpdatePUTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -109,8 +109,7 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -113,8 +113,7 @@ func (m *Module) MediaPUTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package polls
import (
"errors"
"fmt"
"net/http"
"strconv"
@ -89,8 +88,7 @@ func (m *Module) PollVotePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -73,8 +73,7 @@ func (m *Module) ReportPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -76,8 +76,7 @@ func (m *Module) StatusBookmarkPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -79,8 +79,7 @@ func (m *Module) StatusBoostPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -219,8 +219,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -75,8 +75,7 @@ func (m *Module) StatusFavePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -18,7 +18,6 @@
package statuses
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
@ -80,8 +79,7 @@ func (m *Module) StatusMutePOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -81,8 +81,7 @@ func (m *Module) StatusPinPOSTHandler(c *gin.Context) {
}
if authed.Account.IsMoving() {
const text = "your account has Moved or is currently Moving; you cannot take create or update type actions"
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(errors.New(text), text), m.processor.InstanceGetV1)
apiutil.ForbiddenAfterMove(c)
return
}

View file

@ -19,7 +19,6 @@ package streaming
import (
"context"
"errors"
"slices"
"time"
@ -187,8 +186,9 @@ func (m *Module) StreamGETHandler(c *gin.Context) {
}
if account.IsMoving() {
err := errors.New("your account has Moved or is currently Moving; you cannot take create or update type actions")
apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1)
// Moving accounts can't
// use streaming endpoints.
apiutil.NotFoundAfterMove(c)
return
}

View file

@ -184,3 +184,21 @@ func OAuthErrorHandler(c *gin.Context, errWithCode gtserror.WithCode) {
"error_description": errWithCode.Safe(),
})
}
// NotFoundAfterMove returns code 404 to the caller and writes a helpful error message.
// Specifically used for accounts trying to access endpoints they cannot use while moving.
func NotFoundAfterMove(c *gin.Context) {
const errMsg = "your account has Moved or is currently Moving; you cannot use this endpoint"
JSON(c, http.StatusForbidden, map[string]string{
"error": errMsg,
})
}
// ForbiddenAfterMove returns code 403 to the caller and writes a helpful error message.
// Specifically used for accounts trying to take actions on endpoints they cannot do while moving.
func ForbiddenAfterMove(c *gin.Context) {
const errMsg = "your account has Moved or is currently Moving; you cannot take create or update type actions"
JSON(c, http.StatusForbidden, map[string]string{
"error": errMsg,
})
}