summaryrefslogtreecommitdiff
path: root/internal/api/s2s/user/inboxpost.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/api/s2s/user/inboxpost.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/api/s2s/user/inboxpost.go')
-rw-r--r--internal/api/s2s/user/inboxpost.go38
1 files changed, 14 insertions, 24 deletions
diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go
index 6e17850fd..fa6792cd2 100644
--- a/internal/api/s2s/user/inboxpost.go
+++ b/internal/api/s2s/user/inboxpost.go
@@ -19,43 +19,33 @@
package user
import (
- "net/http"
+ "errors"
+ "strings"
"github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/gtserror" //nolint:typecheck
)
// InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
// Eg., POST to https://example.org/users/whatever/inbox.
func (m *Module) InboxPOSTHandler(c *gin.Context) {
- l := logrus.WithFields(logrus.Fields{
- "func": "InboxPOSTHandler",
- "url": c.Request.RequestURI,
- })
-
- requestedUsername := c.Param(UsernameKey)
+ // usernames on our instance are always lowercase
+ requestedUsername := strings.ToLower(c.Param(UsernameKey))
if requestedUsername == "" {
- c.JSON(http.StatusBadRequest, gin.H{"error": "no username specified in request"})
+ err := errors.New("no username specified in request")
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
- ctx := transferContext(c)
-
- posted, err := m.processor.InboxPost(ctx, c.Writer, c.Request)
- if err != nil {
+ if posted, err := m.processor.InboxPost(transferContext(c), c.Writer, c.Request); err != nil {
if withCode, ok := err.(gtserror.WithCode); ok {
- l.Debugf("InboxPOSTHandler: %s", withCode.Error())
- c.JSON(withCode.Code(), withCode.Safe())
- return
+ api.ErrorHandler(c, withCode, m.processor.InstanceGet)
+ } else {
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
}
- l.Debugf("InboxPOSTHandler: error processing request: %s", err)
- c.JSON(http.StatusBadRequest, gin.H{"error": "unable to process request"})
- return
- }
-
- if !posted {
- l.Debugf("InboxPOSTHandler: request could not be handled as an AP request; headers were: %+v", c.Request.Header)
- c.JSON(http.StatusBadRequest, gin.H{"error": "unable to process request"})
+ } else if !posted {
+ err := errors.New("unable to process request")
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
}
}