Returning and handling error from HTTPClientAndScheme

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2016-04-08 12:02:16 -07:00
parent 42fc136b39
commit 1dee9cb3f0
3 changed files with 14 additions and 10 deletions

View File

@ -484,9 +484,9 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
return
}
client, scheme := container.Engine.HTTPClientAndScheme()
if client == nil {
httpError(w, "Cannot connect to docker engine", http.StatusInternalServerError)
client, scheme, err := container.Engine.HTTPClientAndScheme()
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
@ -814,9 +814,9 @@ func postContainersExec(c *context, w http.ResponseWriter, r *http.Request) {
return
}
client, scheme := container.Engine.HTTPClientAndScheme()
if client == nil {
httpError(w, "Cannot connect to docker engine", http.StatusInternalServerError)
client, scheme, err := container.Engine.HTTPClientAndScheme()
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}

View File

@ -93,7 +93,11 @@ func proxyAsync(engine *cluster.Engine, w http.ResponseWriter, r *http.Request,
// RequestURI may not be sent to client
r.RequestURI = ""
client, scheme := engine.HTTPClientAndScheme()
client, scheme, err := engine.HTTPClientAndScheme()
if err != nil {
return err
}
r.URL.Scheme = scheme
r.URL.Host = engine.Addr

View File

@ -147,11 +147,11 @@ func NewEngine(addr string, overcommitRatio float64, opts *EngineOpts) *Engine {
}
// HTTPClientAndScheme returns the underlying HTTPClient and the scheme used by the engine
func (e *Engine) HTTPClientAndScheme() (*http.Client, string) {
func (e *Engine) HTTPClientAndScheme() (*http.Client, string, error) {
if dc, ok := e.client.(*dockerclient.DockerClient); ok {
return dc.HTTPClient, dc.URL.Scheme
return dc.HTTPClient, dc.URL.Scheme, nil
}
return nil, ""
return nil, "", fmt.Errorf("Possibly lost connection to Engine (name: %s, ID: %s) ", e.Name, e.ID)
}
// Connect will initialize a connection to the Docker daemon running on the