Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit fe5a60c

Browse files
committed
Handle precondition errors
1 parent d5adf70 commit fe5a60c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/cmd/errors.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"encoding/json"
5+
"fmt"
56

67
"golang.org/x/xerrors"
78

@@ -47,6 +48,23 @@ func handleAPIError(origError error) error {
4748
}
4849

4950
return clog.Error(origError.Error(), p.Verbose)
51+
case "precondition":
52+
type preconditionPayload struct {
53+
Error string `json:"error"`
54+
Message string `json:"message"`
55+
Solution string `json:"solution"`
56+
}
57+
58+
var p preconditionPayload
59+
err := json.Unmarshal(ae.Err.Details, &p)
60+
if err != nil {
61+
return origError
62+
}
63+
64+
return clog.Error(fmt.Sprintf("Precondition Error : Status Code=%d", httpError.StatusCode),
65+
p.Message,
66+
clog.BlankLine,
67+
clog.Tipf(p.Solution))
5068
}
5169

5270
return origError // Return the original

0 commit comments

Comments
 (0)