diff --git a/commands/deploy.go b/commands/deploy.go index 408405dc..513ffb61 100644 --- a/commands/deploy.go +++ b/commands/deploy.go @@ -75,7 +75,7 @@ func (d *KoolDeploy) Execute(args []string) (err error) { api.SetBaseURL(url) } - d.Shell().Println("Create release file...") + d.Shell().Info("Create release file...") if filename, err = d.createReleaseFile(); err != nil { return } @@ -89,14 +89,14 @@ func (d *KoolDeploy) Execute(args []string) (err error) { deploy = api.NewDeploy(filename) - d.Shell().Println("Upload release file...") + d.Shell().Info("Upload release file...") if err = deploy.SendFile(); err != nil { return } d.Shell().Println("Going to deploy...") - timeout := 10 * time.Minute + timeout := 30 * time.Minute if min, err := strconv.Atoi(d.env.Get("KOOL_API_TIMEOUT")); err == nil { timeout = time.Duration(min) * time.Minute diff --git a/services/cloud/api/deploy.go b/services/cloud/api/deploy.go index a41ac41b..220b9c75 100644 --- a/services/cloud/api/deploy.go +++ b/services/cloud/api/deploy.go @@ -63,6 +63,7 @@ func (d *Deploy) SendFile() (err error) { if errAPI.Status == http.StatusUnauthorized { err = ErrUnauthorized } else if errAPI.Status == http.StatusUnprocessableEntity { + fmt.Println(err) err = ErrPayloadValidation } else if errAPI.Status != http.StatusOK && errAPI.Status != http.StatusCreated { err = ErrBadResponseStatus diff --git a/services/cloud/api/endpoint.go b/services/cloud/api/endpoint.go index 128a4e9a..8f5f1cd9 100644 --- a/services/cloud/api/endpoint.go +++ b/services/cloud/api/endpoint.go @@ -112,7 +112,7 @@ func (e *DefaultEndpoint) DoCall() (err error) { reqURL := fmt.Sprintf("%s/%s?%s", apiBaseURL, e.path, e.query.Encode()) if verbose { - fmt.Fprintf(os.Stderr, "api - calling URL: %s\n", reqURL) + fmt.Fprintf(os.Stderr, "[Kool Cloud] Going to call: %s\n", reqURL) } if request, err = http.NewRequest(e.method, reqURL, body); err != nil { @@ -137,7 +137,7 @@ func (e *DefaultEndpoint) DoCall() (err error) { } if verbose { - fmt.Fprintf(os.Stderr, "api - got response: %s\n", string(raw)) + fmt.Fprintf(os.Stderr, "[Kool Cloud] Got: %s\n", string(raw)) } if e.statusCode >= 400 { diff --git a/services/cloud/api/errors.go b/services/cloud/api/errors.go index 3aca1bf0..f3ceea01 100644 --- a/services/cloud/api/errors.go +++ b/services/cloud/api/errors.go @@ -3,6 +3,7 @@ package api import ( "errors" "fmt" + "strings" ) // ErrBadAPIServer represents some issue in the API side @@ -17,7 +18,7 @@ var ErrDeployFailed error // ErrUnauthorized unauthorized; please check your KOOL_API_TOKEN var ErrUnauthorized error -// ErrPayloadValidation something went wrong validating the payload +// failed validating deploy payload var ErrPayloadValidation error // ErrBadResponseStatus unexpected return status @@ -28,25 +29,29 @@ var ErrUnexpectedResponse error // ErrAPI reprents a default error returned from the API type ErrAPI struct { - Status int - Message string `json:"message"` + Status int - Errors map[string]interface{} `json:"errors"` + Message string `json:"message"` + Errors map[string]interface{} `json:"errors"` } // Error returns the string representation for the error func (e *ErrAPI) Error() string { if e.Errors != nil { - return fmt.Sprintf("%d - %s (%v)", e.Status, e.Message, e.Errors) + s := []string{} + for k, e := range e.Errors { + s = append(s, fmt.Sprintf("\t%s > %v", k, e.([]interface{})[0])) + } + return fmt.Sprintf("\n%d - %s\n\n%s\n", e.Status, e.Message, strings.Join(s, "\n")) } - return fmt.Sprintf("%d - %s", e.Status, e.Message) + return fmt.Sprintf("\n%d - %s\n", e.Status, e.Message) } func init() { ErrBadAPIServer = errors.New("bad API server response") ErrDeployFailed = errors.New("deploy process has failed") ErrUnauthorized = errors.New("unauthorized; please check your KOOL_API_TOKEN") - ErrPayloadValidation = errors.New("something went wrong validating the payload") + ErrPayloadValidation = errors.New("failed validating deploy payload") ErrBadResponseStatus = errors.New("unexpected return status") ErrUnexpectedResponse = errors.New("bad API response; please ask for support") ErrMissingToken = errors.New("missing KOOL_API_TOKEN") diff --git a/services/cloud/api/errors_test.go b/services/cloud/api/errors_test.go index f2de56cb..d82c7a0f 100644 --- a/services/cloud/api/errors_test.go +++ b/services/cloud/api/errors_test.go @@ -25,13 +25,15 @@ func TestDefinedErrors(t *testing.T) { func TestApiErr(t *testing.T) { err := &ErrAPI{100, "message", nil} - if err.Error() != "100 - message" { + if err.Error() != "\n100 - message\n" { t.Errorf("unexpected error message: %s", err.Error()) } - err.Errors = make(map[string]interface{}) + err.Errors = map[string]interface{}{ + "foo": []interface{}{"bar"}, + } - if err.Error() != "100 - message (map[])" { + if err.Error() != "\n100 - message\n\n\tfoo > bar\n" { t.Errorf("unexpected error message: %s", err.Error()) } }