Skip to content

Commit 94d5c8d

Browse files
authored
Merge pull request #397 from kool-dev/deploy-tweaks
Deploy error handling tweaks
2 parents 23b20a9 + 538f7d0 commit 94d5c8d

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

commands/deploy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (d *KoolDeploy) Execute(args []string) (err error) {
7575
api.SetBaseURL(url)
7676
}
7777

78-
d.Shell().Println("Create release file...")
78+
d.Shell().Info("Create release file...")
7979
if filename, err = d.createReleaseFile(); err != nil {
8080
return
8181
}
@@ -89,14 +89,14 @@ func (d *KoolDeploy) Execute(args []string) (err error) {
8989

9090
deploy = api.NewDeploy(filename)
9191

92-
d.Shell().Println("Upload release file...")
92+
d.Shell().Info("Upload release file...")
9393
if err = deploy.SendFile(); err != nil {
9494
return
9595
}
9696

9797
d.Shell().Println("Going to deploy...")
9898

99-
timeout := 10 * time.Minute
99+
timeout := 30 * time.Minute
100100

101101
if min, err := strconv.Atoi(d.env.Get("KOOL_API_TIMEOUT")); err == nil {
102102
timeout = time.Duration(min) * time.Minute

services/cloud/api/deploy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (d *Deploy) SendFile() (err error) {
6363
if errAPI.Status == http.StatusUnauthorized {
6464
err = ErrUnauthorized
6565
} else if errAPI.Status == http.StatusUnprocessableEntity {
66+
fmt.Println(err)
6667
err = ErrPayloadValidation
6768
} else if errAPI.Status != http.StatusOK && errAPI.Status != http.StatusCreated {
6869
err = ErrBadResponseStatus

services/cloud/api/endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (e *DefaultEndpoint) DoCall() (err error) {
112112
reqURL := fmt.Sprintf("%s/%s?%s", apiBaseURL, e.path, e.query.Encode())
113113

114114
if verbose {
115-
fmt.Fprintf(os.Stderr, "api - calling URL: %s\n", reqURL)
115+
fmt.Fprintf(os.Stderr, "[Kool Cloud] Going to call: %s\n", reqURL)
116116
}
117117

118118
if request, err = http.NewRequest(e.method, reqURL, body); err != nil {
@@ -137,7 +137,7 @@ func (e *DefaultEndpoint) DoCall() (err error) {
137137
}
138138

139139
if verbose {
140-
fmt.Fprintf(os.Stderr, "api - got response: %s\n", string(raw))
140+
fmt.Fprintf(os.Stderr, "[Kool Cloud] Got: %s\n", string(raw))
141141
}
142142

143143
if e.statusCode >= 400 {

services/cloud/api/errors.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"errors"
55
"fmt"
6+
"strings"
67
)
78

89
// ErrBadAPIServer represents some issue in the API side
@@ -17,7 +18,7 @@ var ErrDeployFailed error
1718
// ErrUnauthorized unauthorized; please check your KOOL_API_TOKEN
1819
var ErrUnauthorized error
1920

20-
// ErrPayloadValidation something went wrong validating the payload
21+
// failed validating deploy payload
2122
var ErrPayloadValidation error
2223

2324
// ErrBadResponseStatus unexpected return status
@@ -28,25 +29,29 @@ var ErrUnexpectedResponse error
2829

2930
// ErrAPI reprents a default error returned from the API
3031
type ErrAPI struct {
31-
Status int
32-
Message string `json:"message"`
32+
Status int
3333

34-
Errors map[string]interface{} `json:"errors"`
34+
Message string `json:"message"`
35+
Errors map[string]interface{} `json:"errors"`
3536
}
3637

3738
// Error returns the string representation for the error
3839
func (e *ErrAPI) Error() string {
3940
if e.Errors != nil {
40-
return fmt.Sprintf("%d - %s (%v)", e.Status, e.Message, e.Errors)
41+
s := []string{}
42+
for k, e := range e.Errors {
43+
s = append(s, fmt.Sprintf("\t%s > %v", k, e.([]interface{})[0]))
44+
}
45+
return fmt.Sprintf("\n%d - %s\n\n%s\n", e.Status, e.Message, strings.Join(s, "\n"))
4146
}
42-
return fmt.Sprintf("%d - %s", e.Status, e.Message)
47+
return fmt.Sprintf("\n%d - %s\n", e.Status, e.Message)
4348
}
4449

4550
func init() {
4651
ErrBadAPIServer = errors.New("bad API server response")
4752
ErrDeployFailed = errors.New("deploy process has failed")
4853
ErrUnauthorized = errors.New("unauthorized; please check your KOOL_API_TOKEN")
49-
ErrPayloadValidation = errors.New("something went wrong validating the payload")
54+
ErrPayloadValidation = errors.New("failed validating deploy payload")
5055
ErrBadResponseStatus = errors.New("unexpected return status")
5156
ErrUnexpectedResponse = errors.New("bad API response; please ask for support")
5257
ErrMissingToken = errors.New("missing KOOL_API_TOKEN")

services/cloud/api/errors_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ func TestDefinedErrors(t *testing.T) {
2525
func TestApiErr(t *testing.T) {
2626
err := &ErrAPI{100, "message", nil}
2727

28-
if err.Error() != "100 - message" {
28+
if err.Error() != "\n100 - message\n" {
2929
t.Errorf("unexpected error message: %s", err.Error())
3030
}
3131

32-
err.Errors = make(map[string]interface{})
32+
err.Errors = map[string]interface{}{
33+
"foo": []interface{}{"bar"},
34+
}
3335

34-
if err.Error() != "100 - message (map[])" {
36+
if err.Error() != "\n100 - message\n\n\tfoo > bar\n" {
3537
t.Errorf("unexpected error message: %s", err.Error())
3638
}
3739
}

0 commit comments

Comments
 (0)