mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
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
This commit is contained in:
parent
6e33bc48aa
commit
b09595e745
1 changed files with 3 additions and 3 deletions
|
|
@ -424,7 +424,6 @@ func (c *Context) JSONBuf(code int, obj any) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := fmt.Errorf("failed to marshal JSON: %w", err)
|
errMsg := fmt.Errorf("failed to marshal JSON: %w", err)
|
||||||
c.AddError(errMsg)
|
c.AddError(errMsg)
|
||||||
c.Errorf("%s", errMsg)
|
|
||||||
c.ErrorUseHandle(http.StatusInternalServerError, errMsg)
|
c.ErrorUseHandle(http.StatusInternalServerError, errMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -521,8 +520,9 @@ func (c *Context) HTMLBuf(code int, name string, obj any) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := tpl.ExecuteTemplate(&buf, name, obj)
|
err := tpl.ExecuteTemplate(&buf, name, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AddError(fmt.Errorf("failed to render HTML template '%s': %w", name, err))
|
errMsg := 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))
|
c.AddError(errMsg)
|
||||||
|
c.ErrorUseHandle(http.StatusInternalServerError, errMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue