-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle KongService conflict on creation (#749)
- Loading branch information
Showing
16 changed files
with
431 additions
and
71 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,7 +1,67 @@ | ||
package ops | ||
|
||
import "errors" | ||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// ErrNilResponse is an error indicating that a Konnect operation returned an empty response. | ||
// This can sometimes happen regardless of the err being nil. | ||
var ErrNilResponse = errors.New("nil response received") | ||
|
||
// EntityWithMatchingUIDNotFoundError is an error indicating that an entity with a matching UID was not found on Konnect. | ||
type EntityWithMatchingUIDNotFoundError struct { | ||
Entity interface { | ||
GetTypeName() string | ||
GetName() string | ||
GetUID() types.UID | ||
} | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e EntityWithMatchingUIDNotFoundError) Error() string { | ||
return fmt.Sprintf( | ||
"%s %s (matching UID %s) not found on Konnect", | ||
e.Entity.GetTypeName(), e.Entity.GetName(), e.Entity.GetUID(), | ||
) | ||
} | ||
|
||
type sdkErrorBody struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
Details []struct { | ||
TypeAt string `json:"@type"` | ||
Type string `json:"type"` | ||
Field string `json:"field"` | ||
Messages []string `json:"messages"` | ||
} `json:"details"` | ||
} | ||
|
||
// ParseSDKErrorBody parses the body of an SDK error response. | ||
// Exemplary body: | ||
// | ||
// { | ||
// "code": 3, | ||
// "message": "data constraint error", | ||
// "details": [ | ||
// { | ||
// "@type": "type.googleapis.com/kong.admin.model.v1.ErrorDetail", | ||
// "type": "ERROR_TYPE_REFERENCE", | ||
// "field": "name", | ||
// "messages": [ | ||
// "name (type: unique) constraint failed" | ||
// ] | ||
// } | ||
// ] | ||
// } | ||
func ParseSDKErrorBody(body string) (sdkErrorBody, error) { | ||
var sdkErr sdkErrorBody | ||
if err := json.Unmarshal([]byte(body), &sdkErr); err != nil { | ||
return sdkErr, err | ||
} | ||
|
||
return sdkErr, nil | ||
} |
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.