-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
297 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package deckerrors | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
deckutils "github.com/kong/deck/utils" | ||
"github.com/kong/go-kong/kong" | ||
) | ||
|
||
// ConfigConflictError is an error used to wrap deck config conflict errors | ||
// returned from deck functions transforming KongRawState to KongState | ||
// (e.g. state.Get, dump.Get). | ||
type ConfigConflictError struct { | ||
Err error | ||
} | ||
|
||
func (e ConfigConflictError) Error() string { | ||
return e.Err.Error() | ||
} | ||
|
||
func (e ConfigConflictError) Is(err error) bool { | ||
return errors.Is(err, ConfigConflictError{}) | ||
} | ||
|
||
func (e ConfigConflictError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
func IsConflictErr(err error) bool { | ||
var apiErr *kong.APIError | ||
if errors.As(err, &apiErr) && apiErr.Code() == http.StatusConflict || | ||
errors.Is(err, ConfigConflictError{}) { | ||
return true | ||
} | ||
|
||
var deckErrArray deckutils.ErrArray | ||
if errors.As(err, &deckErrArray) { | ||
for _, err := range deckErrArray.Errors { | ||
if IsConflictErr(err) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.