mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03:00
all: use errors.As for inspecting errors that implement httpserver.ErrorWithStatusCode
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -487,8 +488,9 @@ func Errorf(w http.ResponseWriter, format string, args ...interface{}) {
|
||||
|
||||
// Extract statusCode from args
|
||||
statusCode := http.StatusBadRequest
|
||||
var esc *ErrorWithStatusCode
|
||||
for _, arg := range args {
|
||||
if esc, ok := arg.(*ErrorWithStatusCode); ok {
|
||||
if err, ok := arg.(error); ok && errors.As(err, &esc) {
|
||||
statusCode = esc.StatusCode
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user