summaryrefslogtreecommitdiff
path: root/internal/api/util/errorhandling.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-08 14:32:17 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-08 14:32:17 +0000
commite9e5dc5a40926e5320cb131b035c46b1e1b0bd59 (patch)
tree52edc9fa5742f28e1e5223f51cda628ec1c35a24 /internal/api/util/errorhandling.go
parent[chore]: Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2338) (diff)
downloadgotosocial-e9e5dc5a40926e5320cb131b035c46b1e1b0bd59.tar.xz
[feature] add support for polls + receiving federated status edits (#2330)
Diffstat (limited to 'internal/api/util/errorhandling.go')
-rw-r--r--internal/api/util/errorhandling.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/internal/api/util/errorhandling.go b/internal/api/util/errorhandling.go
index 9128ce499..33f501474 100644
--- a/internal/api/util/errorhandling.go
+++ b/internal/api/util/errorhandling.go
@@ -40,7 +40,7 @@ import (
// 404 header and footer.
//
// If an error is returned by InstanceGet, the function will panic.
-func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string) {
+func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string, errWithCode gtserror.WithCode) {
switch accept {
case string(TextHTML):
ctx := c.Request.Context()
@@ -54,9 +54,7 @@ func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*api
"requestID": gtscontext.RequestID(ctx),
})
default:
- c.JSON(http.StatusNotFound, gin.H{
- "error": http.StatusText(http.StatusNotFound),
- })
+ c.JSON(http.StatusNotFound, gin.H{"error": errWithCode.Safe()})
}
}
@@ -122,7 +120,7 @@ func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet fun
if errWithCode.Code() == http.StatusNotFound {
// Use our special not found handler with useful status text.
- NotFoundHandler(c, instanceGet, accept)
+ NotFoundHandler(c, instanceGet, accept, errWithCode)
} else {
genericErrorHandler(c, instanceGet, accept, errWithCode)
}