tsweb: when unwrapping HTTPError, record the user-facing message also in the log
There's often some useful piece of information in there not already repeated in the internal error. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
dea3ef0597
commit
815bf017fc
|
@ -58,6 +58,9 @@ func (fn JSONHandlerFunc) ServeHTTPReturn(w http.ResponseWriter, r *http.Request
|
||||||
// the client in this handler. We don't want the wrapping
|
// the client in this handler. We don't want the wrapping
|
||||||
// ReturnHandler to do it too.
|
// ReturnHandler to do it too.
|
||||||
err = werr.Err
|
err = werr.Err
|
||||||
|
if werr.Msg != "" {
|
||||||
|
err = fmt.Errorf("%s: %w", werr.Msg, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resp = &response{
|
resp = &response{
|
||||||
Status: "error",
|
Status: "error",
|
||||||
|
|
|
@ -236,8 +236,13 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
case hErrOK:
|
case hErrOK:
|
||||||
// Handler asked us to send an error. Do so, if we haven't
|
// Handler asked us to send an error. Do so, if we haven't
|
||||||
// already sent a response.
|
// already sent a response.
|
||||||
|
msg.Err = hErr.Msg
|
||||||
if hErr.Err != nil {
|
if hErr.Err != nil {
|
||||||
msg.Err = hErr.Err.Error()
|
if msg.Err == "" {
|
||||||
|
msg.Err = hErr.Err.Error()
|
||||||
|
} else {
|
||||||
|
msg.Err = msg.Err + ": " + hErr.Err.Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if lw.code != 0 {
|
if lw.code != 0 {
|
||||||
h.logf("[unexpected] handler returned HTTPError %v, but already sent a response with code %d", hErr, lw.code)
|
h.logf("[unexpected] handler returned HTTPError %v, but already sent a response with code %d", hErr, lw.code)
|
||||||
|
|
|
@ -122,7 +122,7 @@ func TestStdHandler(t *testing.T) {
|
||||||
Host: "example.com",
|
Host: "example.com",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
RequestURI: "/foo",
|
RequestURI: "/foo",
|
||||||
Err: testErr.Error(),
|
Err: "not found: " + testErr.Error(),
|
||||||
Code: 404,
|
Code: 404,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -139,6 +139,7 @@ func TestStdHandler(t *testing.T) {
|
||||||
Host: "example.com",
|
Host: "example.com",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
RequestURI: "/foo",
|
RequestURI: "/foo",
|
||||||
|
Err: "not found",
|
||||||
Code: 404,
|
Code: 404,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -189,7 +190,7 @@ func TestStdHandler(t *testing.T) {
|
||||||
Host: "example.com",
|
Host: "example.com",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
RequestURI: "/foo",
|
RequestURI: "/foo",
|
||||||
Err: testErr.Error(),
|
Err: "not found: " + testErr.Error(),
|
||||||
Code: 200,
|
Code: 200,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue