Move network timeout handling back in UnroutedHandler
This commit is contained in:
parent
74fca8c6c3
commit
c8b8703bb1
13
metrics.go
13
metrics.go
|
@ -2,7 +2,6 @@ package tusd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
@ -88,18 +87,8 @@ type simpleHTTPError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func simplifyHTTPError(err HTTPError) simpleHTTPError {
|
func simplifyHTTPError(err HTTPError) simpleHTTPError {
|
||||||
var msg string
|
|
||||||
// Errors for read timeouts contain too much information which is not
|
|
||||||
// necessary for us and makes grouping for the metrics harder. The error
|
|
||||||
// message looks like: read tcp 127.0.0.1:1080->127.0.0.1:53673: i/o timeout
|
|
||||||
// Therefore, we use a common error message for all of them.
|
|
||||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
|
||||||
msg = "read tcp: i/o timeout"
|
|
||||||
} else {
|
|
||||||
msg = err.Error()
|
|
||||||
}
|
|
||||||
return simpleHTTPError{
|
return simpleHTTPError{
|
||||||
Message: msg,
|
Message: err.Error(),
|
||||||
StatusCode: err.StatusCode(),
|
StatusCode: err.StatusCode(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -611,6 +612,14 @@ func (handler *UnroutedHandler) sendError(w http.ResponseWriter, r *http.Request
|
||||||
err = ErrNotFound
|
err = ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errors for read timeouts contain too much information which is not
|
||||||
|
// necessary for us and makes grouping for the metrics harder. The error
|
||||||
|
// message looks like: read tcp 127.0.0.1:1080->127.0.0.1:53673: i/o timeout
|
||||||
|
// Therefore, we use a common error message for all of them.
|
||||||
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||||
|
err = errors.New("read tcp: i/o timeout")
|
||||||
|
}
|
||||||
|
|
||||||
statusErr, ok := err.(HTTPError)
|
statusErr, ok := err.(HTTPError)
|
||||||
if !ok {
|
if !ok {
|
||||||
statusErr = NewHTTPError(err, http.StatusInternalServerError)
|
statusErr = NewHTTPError(err, http.StatusInternalServerError)
|
||||||
|
|
Loading…
Reference in New Issue