tsweb: allow HTTPError to unwrap errors
Signed-off-by: Will Norris <will@tailscale.com>pull/5703/merge
parent
2243dbccb7
commit
62bc1052a2
|
@ -421,6 +421,8 @@ type HTTPError struct {
|
|||
// Error implements the error interface.
|
||||
func (e HTTPError) Error() string { return fmt.Sprintf("httperror{%d, %q, %v}", e.Code, e.Msg, e.Err) }
|
||||
|
||||
func (e HTTPError) Unwrap() error { return e.Err }
|
||||
|
||||
// Error returns an HTTPError containing the given information.
|
||||
func Error(code int, msg string, err error) HTTPError {
|
||||
return HTTPError{Code: code, Msg: msg, Err: err}
|
||||
|
|
|
@ -327,6 +327,14 @@ func BenchmarkLog(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHTTPError_Unwrap(t *testing.T) {
|
||||
wrappedErr := fmt.Errorf("wrapped")
|
||||
err := Error(404, "not found", wrappedErr)
|
||||
if got := errors.Unwrap(err); got != wrappedErr {
|
||||
t.Errorf("HTTPError.Unwrap() = %v, want %v", got, wrappedErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVarzHandler(t *testing.T) {
|
||||
t.Run("globals_log", func(t *testing.T) {
|
||||
rec := httptest.NewRecorder()
|
||||
|
|
Loading…
Reference in New Issue