From b09595e745572d2660030858671bdb3b768eec5c Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 29 Mar 2026 23:43:29 +0800 Subject: [PATCH] fix: address PR #73 review feedback - Remove redundant c.Errorf call in JSONBuf - Consolidate error wrapping in HTMLBuf to avoid duplicate fmt.Errorf calls - Keep error handling consistent across all Buf methods --- context.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index 2c51e99..22f67ea 100644 --- a/context.go +++ b/context.go @@ -424,7 +424,6 @@ func (c *Context) JSONBuf(code int, obj any) { if err != nil { errMsg := fmt.Errorf("failed to marshal JSON: %w", err) c.AddError(errMsg) - c.Errorf("%s", errMsg) c.ErrorUseHandle(http.StatusInternalServerError, errMsg) return } @@ -521,8 +520,9 @@ func (c *Context) HTMLBuf(code int, name string, obj any) { var buf bytes.Buffer err := tpl.ExecuteTemplate(&buf, name, obj) if err != nil { - c.AddError(fmt.Errorf("failed to render HTML template '%s': %w", name, err)) - c.ErrorUseHandle(http.StatusInternalServerError, fmt.Errorf("failed to render HTML template '%s': %w", name, err)) + errMsg := fmt.Errorf("failed to render HTML template '%s': %w", name, err) + c.AddError(errMsg) + c.ErrorUseHandle(http.StatusInternalServerError, errMsg) return } c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")