From ba5a464ca5d3fcbd171c174a4f07c3326ecb01df Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Fri, 12 May 2023 08:16:41 +0000 Subject: [chore] Prefer JSON errors in API endpoints (#1766) * Default to JSON over HTML for error handling * Change the default error display for web endpoints to html --- internal/web/profile.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'internal/web/profile.go') diff --git a/internal/web/profile.go b/internal/web/profile.go index 71bfe6c82..a4fddbafe 100644 --- a/internal/web/profile.go +++ b/internal/web/profile.go @@ -44,20 +44,20 @@ func (m *Module) profileGETHandler(c *gin.Context) { authed, err := oauth.Authed(c, false, false, false, false) if err != nil { - apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) + apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) return } username := strings.ToLower(c.Param(usernameKey)) if username == "" { err := errors.New("no account username specified") - apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) + apiutil.WebErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) return } instance, err := m.processor.InstanceGetV1(ctx) if err != nil { - apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1) + apiutil.WebErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1) return } @@ -67,7 +67,7 @@ func (m *Module) profileGETHandler(c *gin.Context) { account, errWithCode := m.processor.Account().GetLocalByUsername(ctx, authed.Account, username) if errWithCode != nil { - apiutil.ErrorHandler(c, errWithCode, instanceGet) + apiutil.WebErrorHandler(c, errWithCode, instanceGet) return } @@ -105,7 +105,7 @@ func (m *Module) profileGETHandler(c *gin.Context) { statusResp, errWithCode := m.processor.Account().WebStatusesGet(ctx, account.ID, maxStatusID) if errWithCode != nil { - apiutil.ErrorHandler(c, errWithCode, instanceGet) + apiutil.WebErrorHandler(c, errWithCode, instanceGet) return } @@ -116,7 +116,7 @@ func (m *Module) profileGETHandler(c *gin.Context) { if !paging { pinnedResp, errWithCode = m.processor.Account().StatusesGet(ctx, authed.Account, account.ID, 0, false, false, "", "", true, false, false) if errWithCode != nil { - apiutil.ErrorHandler(c, errWithCode, instanceGet) + apiutil.WebErrorHandler(c, errWithCode, instanceGet) return } } @@ -158,14 +158,14 @@ func (m *Module) returnAPProfile(ctx context.Context, c *gin.Context, username s user, errWithCode := m.processor.Fedi().UserGet(ctx, username, c.Request.URL) if errWithCode != nil { - apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) //nolint:contextcheck + apiutil.WebErrorHandler(c, errWithCode, m.processor.InstanceGetV1) //nolint:contextcheck return } b, mErr := json.Marshal(user) if mErr != nil { err := fmt.Errorf("could not marshal json: %s", mErr) - apiutil.ErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1) //nolint:contextcheck + apiutil.WebErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1) //nolint:contextcheck return } -- cgit v1.2.3