summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-04 23:25:59 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-04-04 23:25:59 +0900
commitdd23afaff4fdd47442be82318e5dc4556404b90d (patch)
tree02281d0e906a2802226b96b115dd7087b3749458
parent1a72f3c41b3e7ad076a5fd8e020f26f35b9e4a62 (diff)
gobgp: show http error when request failed
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--gobgp/main.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/gobgp/main.go b/gobgp/main.go
index 364dc963..fd761da2 100644
--- a/gobgp/main.go
+++ b/gobgp/main.go
@@ -21,10 +21,15 @@ import (
"github.com/jessevdk/go-flags"
"github.com/parnurzeal/gorequest"
"net"
+ "net/http"
"os"
"sort"
)
+func isError(resp *http.Response) bool {
+ return resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated
+}
+
func execute(resource string, callback func(url string, r *gorequest.SuperAgent) *gorequest.SuperAgent) []byte {
r := gorequest.New()
url := globalOpts.URL + ":" + fmt.Sprint(globalOpts.Port) + "/v1/bgp/" + resource
@@ -32,7 +37,7 @@ func execute(resource string, callback func(url string, r *gorequest.SuperAgent)
fmt.Println(url)
}
r = callback(url, r)
- _, body, err := r.End()
+ resp, body, err := r.End()
if err != nil {
fmt.Print("Failed to connect to gobgpd. It runs?\n")
if globalOpts.Debug {
@@ -40,8 +45,11 @@ func execute(resource string, callback func(url string, r *gorequest.SuperAgent)
}
os.Exit(1)
}
- if globalOpts.Debug {
+ if globalOpts.Debug || isError(resp) {
fmt.Println(body)
+ if isError(resp) {
+ os.Exit(1)
+ }
}
return []byte(body)
}