MCPcopy
hub / github.com/AdguardTeam/AdGuardHome / ErrorAndLog

Function ErrorAndLog

internal/aghhttp/aghhttp.go:31–53  ·  view source on GitHub ↗

ErrorAndLog writes a formatted HTTP error response and logs it at [slog.LevelError] level. l, r, and w must not be nil.

(
	ctx context.Context,
	l *slog.Logger,
	r *http.Request,
	w http.ResponseWriter,
	code int,
	format string,
	args ...any,
)

Source from the content-addressed store, hash-verified

29// ErrorAndLog writes a formatted HTTP error response and logs it at
30// [slog.LevelError] level. l, r, and w must not be nil.
31func ErrorAndLog(
32 ctx context.Context,
33 l *slog.Logger,
34 r *http.Request,
35 w http.ResponseWriter,
36 code int,
37 format string,
38 args ...any,
39) {
40 text := fmt.Sprintf(format, args...)
41 l.WarnContext(
42 ctx,
43 "http error",
44 "host", r.Host,
45 "method", r.Method,
46 "raddr", r.RemoteAddr,
47 "request_uri", r.RequestURI,
48 "status", code,
49 slogutil.KeyError, text,
50 )
51
52 http.Error(w, text, code)
53}
54
55// UserAgent returns the ID of the service as a User-Agent string. It can also
56// be used as the value of the Server HTTP header.

Callers 15

handleSetConfigMethod · 0.92
handleTestUpstreamDNSMethod · 0.92
handleSetProtectionMethod · 0.92
handleAccessSetMethod · 0.92
handleLoginMethod · 0.92
finalizeInstallMethod · 0.92
handleVersionJSONMethod · 0.92
handleUpdateMethod · 0.92
handlePutProfileMethod · 0.92

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…