summaryrefslogtreecommitdiff
path: root/internal/api/client/admin/domainblockdelete.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/admin/domainblockdelete.go')
-rw-r--r--internal/api/client/admin/domainblockdelete.go38
1 files changed, 19 insertions, 19 deletions
diff --git a/internal/api/client/admin/domainblockdelete.go b/internal/api/client/admin/domainblockdelete.go
index 8d41ec072..416db002b 100644
--- a/internal/api/client/admin/domainblockdelete.go
+++ b/internal/api/client/admin/domainblockdelete.go
@@ -1,11 +1,13 @@
package admin
import (
+ "errors"
+ "fmt"
"net/http"
"github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
@@ -36,48 +38,46 @@ import (
// description: The domain block that was just deleted.
// schema:
// "$ref": "#/definitions/domainBlock"
-// '403':
-// description: forbidden
// '400':
// description: bad request
+// '401':
+// description: unauthorized
+// '403':
+// description: forbidden
// '404':
// description: not found
+// '406':
+// description: not acceptable
+// '500':
+// description: internal server error
func (m *Module) DomainBlockDELETEHandler(c *gin.Context) {
- l := logrus.WithFields(logrus.Fields{
- "func": "DomainBlockDELETEHandler",
- "request_uri": c.Request.RequestURI,
- "user_agent": c.Request.UserAgent(),
- "origin_ip": c.ClientIP(),
- })
-
- // make sure we're authed with an admin account
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
- l.Debugf("couldn't auth: %s", err)
- c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
+ api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
return
}
+
if !authed.User.Admin {
- l.Debugf("user %s not an admin", authed.User.ID)
- c.JSON(http.StatusForbidden, gin.H{"error": "not an admin"})
+ err := fmt.Errorf("user %s not an admin", authed.User.ID)
+ api.ErrorHandler(c, gtserror.NewErrorForbidden(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
}
domainBlockID := c.Param(IDKey)
if domainBlockID == "" {
- c.JSON(http.StatusBadRequest, gin.H{"error": "no domain block id provided"})
+ err := errors.New("no domain block id specified")
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
domainBlock, errWithCode := m.processor.AdminDomainBlockDelete(c.Request.Context(), authed, domainBlockID)
if errWithCode != nil {
- l.Debugf("error deleting domain block: %s", errWithCode.Error())
- c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
+ api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
return
}