From af323c70061ad41f1ff2249f0406421887302794 Mon Sep 17 00:00:00 2001
From: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Date: Wed, 2 Sep 2015 16:12:19 -0700
Subject: [PATCH] Don't discard error message on sending response Error
 messages are always discarded and it makes diagnostic difficult when error
 occurs.

Before:
$ dnet network create -d overlay ov1
error : ""
$ docker network create -d overlay ov1
Error response from daemon: ""

After:
$ dnet network create -d overlay ov1
error : "no datastore configured. cannot obtain vxlan id"
$ docker network create -d overlay ov1
Error response from daemon: "no datastore configured. cannot obtain vxlan id"

Breakage caused by  11094f2

Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
---
 libnetwork/api/api.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libnetwork/api/api.go b/libnetwork/api/api.go
index 12cefe138b..07ebf8bf59 100644
--- a/libnetwork/api/api.go
+++ b/libnetwork/api/api.go
@@ -168,6 +168,10 @@ func makeHandler(ctrl libnetwork.NetworkController, fct processor) http.HandlerF
 		}
 
 		res, rsp := fct(ctrl, mux.Vars(req), body)
+		if !rsp.isOK() {
+			http.Error(w, rsp.Status, rsp.StatusCode)
+			return
+		}
 		if res != nil {
 			writeJSON(w, rsp.StatusCode, res)
 		}