Commit 9a939073 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Make 502 errors easier to spot in Sentry

parent 91ec241b
......@@ -4,7 +4,8 @@ Formerly known as 'gitlab-git-http-server'.
v0.8.2 (not released yet)
Recognize more archive formats in git.SendArchive.
Recognize more archive formats in git.SendArchive. Make 502 errors
(failed proxy requests to Unicorn) easier to recognize in Sentry.
v0.8.1
......
......@@ -24,6 +24,9 @@ var DefaultTransport = &http.Transport{
TLSHandshakeTimeout: 10 * time.Second, // from http.DefaultTransport
}
// Custom error for pretty Sentry 'issues'
type Error502 error
type RoundTripper struct {
Transport *http.Transport
}
......@@ -68,6 +71,7 @@ func mustParseAddress(address, scheme string) string {
}
func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error) {
start := time.Now()
res, err = t.Transport.RoundTrip(r)
// httputil.ReverseProxy translates all errors from this
......@@ -77,7 +81,9 @@ func (t *RoundTripper) RoundTrip(r *http.Request) (res *http.Response, err error
// instead of 500s we catch the RoundTrip error here and inject a
// 502 response.
if err != nil {
helper.LogError(fmt.Errorf("proxyRoundTripper: %s %q failed with: %q", r.Method, r.RequestURI, err))
helper.LogError(Error502(fmt.Errorf("badgateway: %s %q failed after %.3fs: %v",
r.Method, r.RequestURI, time.Since(start).Seconds(), err,
)))
res = &http.Response{
StatusCode: http.StatusBadGateway,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment