mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-06-12 10:19:23 +00:00
replace repeated text with error func
This commit is contained in:
parent
f899017b68
commit
322d3c5ffb
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue