Handle HTTP 409 error messages properly for Pod actions

This PR fixes the case when the API return HTTP 409 response. Where the
API return the body format different then for other HTTP error codes.

Signed-off-by: Ondra Machacek <omachace@redhat.com>
This commit is contained in:
Ondra Machacek
2021-10-20 18:45:56 +02:00
parent 3147ff829b
commit f2115471dd
11 changed files with 94 additions and 23 deletions

View File

@ -83,6 +83,12 @@ func Contains(err error, sub error) bool {
return strings.Contains(err.Error(), sub.Error())
}
// PodConflictErrorModel is used in remote connections with podman
type PodConflictErrorModel struct {
Errs []string
Id string //nolint
}
// ErrorModel is used in remote connections with podman
type ErrorModel struct {
// API root cause formatted for automated parsing
@ -106,3 +112,11 @@ func (e ErrorModel) Cause() error {
func (e ErrorModel) Code() int {
return e.ResponseCode
}
func (e PodConflictErrorModel) Error() string {
return strings.Join(e.Errs, ",")
}
func (e PodConflictErrorModel) Code() int {
return 409
}