welcome: dump error message as response
diff --git a/core/auth/ui/api.go b/core/auth/ui/api.go
index 6d14899..a0065a6 100644
--- a/core/auth/ui/api.go
+++ b/core/auth/ui/api.go
@@ -4,6 +4,7 @@
"bytes"
"encoding/json"
"fmt"
+ "io"
"net/http"
"github.com/gorilla/mux"
@@ -60,9 +61,16 @@
var buf bytes.Buffer
fmt.Fprintf(&buf, identityCreateTmpl, req.Password, req.Username)
resp, err := http.Post(s.identitiesEndpoint(), "application/json", &buf)
- if err != nil || resp.StatusCode != http.StatusCreated {
+ if err != nil {
http.Error(w, "failed", http.StatusInternalServerError)
return
+ } else if resp.StatusCode != http.StatusCreated {
+ var buf bytes.Buffer
+ if _, err := io.Copy(&buf, resp.Body); err != nil {
+ http.Error(w, "failed to copy response body", http.StatusInternalServerError)
+ } else {
+ http.Error(w, buf.String(), resp.StatusCode)
+ }
}
}
diff --git a/core/installer/welcome/welcome.go b/core/installer/welcome/welcome.go
index 9c672de..60adf6b 100644
--- a/core/installer/welcome/welcome.go
+++ b/core/installer/welcome/welcome.go
@@ -117,7 +117,13 @@
}
resp, err := http.Post(s.createAccountAddr, "application/json", &buf)
if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
+ var respBody bytes.Buffer
+ if _, err := io.Copy(&respBody, resp.Body); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ }
+ respStr := respBody.String()
+ log.Println(respStr)
+ http.Error(w, respStr, http.StatusInternalServerError)
return
}
// TODO(gio): better handle status code and error message