summaryrefslogtreecommitdiff
path: root/internal/api/client/admin/domainblocksget.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/admin/domainblocksget.go')
-rw-r--r--internal/api/client/admin/domainblocksget.go50
1 files changed, 28 insertions, 22 deletions
diff --git a/internal/api/client/admin/domainblocksget.go b/internal/api/client/admin/domainblocksget.go
index 94b1c89ce..d585e837d 100644
--- a/internal/api/client/admin/domainblocksget.go
+++ b/internal/api/client/admin/domainblocksget.go
@@ -1,12 +1,14 @@
package admin
import (
+ "errors"
+ "fmt"
"net/http"
"strconv"
"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"
)
@@ -43,35 +45,40 @@ import (
// type: array
// items:
// "$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) DomainBlocksGETHandler(c *gin.Context) {
- l := logrus.WithFields(logrus.Fields{
- "func": "DomainBlocksGETHandler",
- "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 == "" {
+ err := errors.New("no domain block id specified")
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
@@ -80,17 +87,16 @@ func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
if exportString != "" {
i, err := strconv.ParseBool(exportString)
if err != nil {
- l.Debugf("error parsing export string: %s", err)
- c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse export query param"})
+ err := fmt.Errorf("error parsing %s: %s", ExportQueryKey, err)
+ api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
return
}
export = i
}
- domainBlocks, err := m.processor.AdminDomainBlocksGet(c.Request.Context(), authed, export)
- if err != nil {
- l.Debugf("error getting domain blocks: %s", err)
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ domainBlocks, errWithCode := m.processor.AdminDomainBlocksGet(c.Request.Context(), authed, export)
+ if errWithCode != nil {
+ api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
return
}