diff options
author | 2023-11-27 14:00:57 +0000 | |
---|---|---|
committer | 2023-11-27 14:00:57 +0000 | |
commit | 74700cc8034980334e7df466f313287a41d2b8a6 (patch) | |
tree | 63ab8912c813eefba8a492e0d0489f4e5fe59446 /internal/api/util/errorhandling.go | |
parent | [chore]: Bump codeberg.org/gruf/go-mutexes from 1.3.0 to 1.3.1 (#2387) (diff) | |
download | gotosocial-74700cc8034980334e7df466f313287a41d2b8a6.tar.xz |
[performance] http response encoding / writing improvements (#2374)
Diffstat (limited to 'internal/api/util/errorhandling.go')
-rw-r--r-- | internal/api/util/errorhandling.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/internal/api/util/errorhandling.go b/internal/api/util/errorhandling.go index 4fa544ffd..8bb251040 100644 --- a/internal/api/util/errorhandling.go +++ b/internal/api/util/errorhandling.go @@ -55,7 +55,9 @@ func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*api "requestID": gtscontext.RequestID(ctx), }) default: - c.JSON(http.StatusNotFound, gin.H{"error": errWithCode.Safe()}) + JSON(c, http.StatusNotFound, map[string]string{ + "error": errWithCode.Safe(), + }) } } @@ -78,7 +80,9 @@ func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context) ( "requestID": gtscontext.RequestID(ctx), }) default: - c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()}) + JSON(c, errWithCode.Code(), map[string]string{ + "error": errWithCode.Safe(), + }) } } @@ -102,7 +106,7 @@ func ErrorHandler( c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), - offers ...MIME, + offers ...string, ) { if ctxErr := c.Request.Context().Err(); ctxErr != nil { // Context error means either client has left already, @@ -175,7 +179,7 @@ func OAuthErrorHandler(c *gin.Context, errWithCode gtserror.WithCode) { l.Debug("handling OAuth error") } - c.JSON(statusCode, gin.H{ + JSON(c, statusCode, map[string]string{ "error": errWithCode.Error(), "error_description": errWithCode.Safe(), }) |