cmd/coordinator: make gomote proxy 502 error include detail

Go 1.11 added ReverseProxy.ErrorHandler; use it to make the
httputil.ReverseProxy failures print the underlying error back to the
(trusted) client. (Normally the client isn't necessarily trusted
enough to get the full info)

Also, log more to stderr where we can search for it.

Updates golang/go#28365

Change-Id: Iac2d863b159f24fda2e0e6e1f7374ed05434d3e4
Reviewed-on: https://go-review.googlesource.com/c/build/+/200738
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/cmd/coordinator/remote.go b/cmd/coordinator/remote.go
index 1f5d57b..3186ac1 100644
--- a/cmd/coordinator/remote.go
+++ b/cmd/coordinator/remote.go
@@ -316,6 +316,11 @@
 		Director:      func(*http.Request) {}, // nothing
 		Transport:     rb.buildlet.ProxyRoundTripper(),
 		FlushInterval: 500 * time.Millisecond,
+		ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
+			log.Printf("gomote proxy error for %s: %v", buildletName, err)
+			w.WriteHeader(http.StatusBadGateway)
+			fmt.Fprintf(w, "(golang.org/issue/28365): gomote proxy error: %v", err)
+		},
 	}
 	proxy.ServeHTTP(w, outReq)
 }