summaryrefslogtreecommitdiff
path: root/internal/api/client/account/follow.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/account/follow.go')
-rw-r--r--internal/api/client/account/follow.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/internal/api/client/account/follow.go b/internal/api/client/account/follow.go
index b17dd9636..11bfbf965 100644
--- a/internal/api/client/account/follow.go
+++ b/internal/api/client/account/follow.go
@@ -19,11 +19,13 @@
package account
import (
+ "errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
@@ -75,39 +77,45 @@ import (
// description: Your relationship to this account.
// schema:
// "$ref": "#/definitions/accountRelationship"
-// '401':
-// description: unauthorized
// '400':
// description: bad request
+// '401':
+// description: unauthorized
// '404':
// description: not found
+// '406':
+// description: not acceptable
+// '500':
+// description: internal server error
func (m *Module) AccountFollowPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
- c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
+ api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
return
}
if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil {
- c.JSON(http.StatusNotAcceptable, gin.H{"error": err.Error()})
+ api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet)
return
}
targetAcctID := c.Param(IDKey)
if targetAcctID == "" {
- c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"})
+ err := errors.New("no account id specified")
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
+
form := &model.AccountFollowRequest{}
if err := c.ShouldBind(form); err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
form.ID = targetAcctID
relationship, errWithCode := m.processor.AccountFollowCreate(c.Request.Context(), authed, form)
if errWithCode != nil {
- c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
+ api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
return
}