Skip to content

Commit db34fb1

Browse files
committed
refactor(http): standardize list-load logging
1 parent a2d9286 commit db34fb1

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

services/merrymaker-go/internal/http/ui_allowlist.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ func (h *UIHandlers) Allowlist(w http.ResponseWriter, r *http.Request) {
2020
listOpts := model.DomainAllowlistListOptions{Limit: limit, Offset: offset}
2121
items, err := h.AllowlistSvc.List(ctx, listOpts)
2222
if err != nil {
23-
h.logger().Error("failed to load allowlist for UI",
24-
"error", err,
23+
h.logLoadError(ctx, "failed to load allowlist for UI", err,
2524
"page", pg.Page,
2625
"page_size", pg.PageSize,
2726
)

services/merrymaker-go/internal/http/ui_base.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ func (h *UIHandlers) handleDelete(w http.ResponseWriter, r *http.Request, opts d
270270
}
271271
}
272272

273+
// logLoadError standardizes list-load error logging with request context.
274+
func (h *UIHandlers) logLoadError(ctx context.Context, message string, err error, attrs ...any) {
275+
args := append([]any{"error", err}, attrs...)
276+
h.logger().ErrorContext(ctx, message, args...)
277+
}
278+
273279
// triggerToast sends a standardized HX-Trigger payload for toast notifications.
274280
// Centralizing this avoids repeating the boilerplate map construction across handlers.
275281
func triggerToast(w http.ResponseWriter, message, toastType string) {

services/merrymaker-go/internal/http/ui_dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (h *UIHandlers) Alerts(w http.ResponseWriter, r *http.Request) {
261261
pageOpts{Page: pageNum, PageSize: pageSize},
262262
)
263263
if err != nil {
264-
h.logger().Error("failed to load alerts for UI", "error", err)
264+
h.logLoadError(r.Context(), "failed to load alerts for UI", err)
265265
page.Error = true
266266
page.ErrorMessage = errMsgUnableLoadAlerts
267267
h.renderDashboardPage(w, r, page)

services/merrymaker-go/internal/http/ui_sites.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ func (h *UIHandlers) Sites(w http.ResponseWriter, r *http.Request) {
134134
rows, err := h.listSiteRows(ctx, filters, pageBounds{Limit: limit, Offset: offset})
135135
if err != nil {
136136
// Log the error for operational visibility
137-
h.logger().Error("failed to load sites for UI",
138-
"error", err,
137+
h.logLoadError(ctx, "failed to load sites for UI", err,
139138
"query", filters.Q,
140139
"enabled", filters.Enabled,
141140
"scope", filters.Scope,

0 commit comments

Comments
 (0)