MCPcopy Index your code
hub / github.com/VictoriaMetrics/VictoriaLogs / Errorf

Function Errorf

lib/httpserver/httpserver.go:654–679  ·  view source on GitHub ↗

Errorf writes formatted error message to w and to logger.

(w http.ResponseWriter, r *http.Request, format string, args ...any)

Source from the content-addressed store, hash-verified

652
653// Errorf writes formatted error message to w and to logger.
654func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...any) {
655 errStr := fmt.Sprintf(format, args...)
656 remoteAddr := GetQuotedRemoteAddr(r)
657 requestURI := GetRequestURI(r)
658 errStr = fmt.Sprintf("remoteAddr: %s; requestURI: %s; %s", remoteAddr, requestURI, errStr)
659 logger.WarnfSkipframes(1, "%s", errStr)
660
661 // Extract statusCode from args
662 statusCode := http.StatusBadRequest
663 var esc *ErrorWithStatusCode
664 for _, arg := range args {
665 if err, ok := arg.(error); ok && errors.As(err, &esc) {
666 statusCode = esc.StatusCode
667 break
668 }
669 }
670
671 if rwa, ok := w.(*responseWriterWithAbort); ok && rwa.sentHeaders {
672 // HTTP status code has been already sent to client, so it cannot be sent again.
673 // Just write errStr to the response and abort the client connection, so the client could notice the error.
674 fmt.Fprintf(w, "\n%s\n", errStr)
675 rwa.abort()
676 return
677 }
678 http.Error(w, errStr, statusCode)
679}
680
681// ErrorWithStatusCode is error with HTTP status code.
682//

Callers 15

newRequestHandlerFunction · 0.92
handlerMethod · 0.92
RequestHandlerFunction · 0.92
RequestHandlerFunction · 0.92
UnitTestFunction · 0.92
requestHandlerFunction · 0.92
RequestHandlerFunction · 0.92
RequestHandlerFunction · 0.92
RequestHandlerFunction · 0.92
handleProtobufFunction · 0.92

Calls 5

WarnfSkipframesFunction · 0.92
GetQuotedRemoteAddrFunction · 0.85
GetRequestURIFunction · 0.85
abortMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…