From 5aa4dc347ee85e4aa2e9b5634211589f6c22b317 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Mon, 7 Aug 2023 14:00:56 +0300 Subject: [PATCH] add error struct for 409 conflict errors Distinguishing conflict errors is useful for clients attempting to do retries when an operation is rejected because of the lock being already taken Signed-off-by: Benny Zlotnik --- sdk/ovirtsdk/error.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sdk/ovirtsdk/error.go b/sdk/ovirtsdk/error.go index 85d6560..02fd929 100644 --- a/sdk/ovirtsdk/error.go +++ b/sdk/ovirtsdk/error.go @@ -26,6 +26,12 @@ type AuthError struct { baseError } +// Conflict error indicates that the operation failed because of a conflict. +// For example, another operation block the operation from being executed. +type ConflictError struct { + baseError +} + // NotFoundError indicates that an object can't be found. type NotFoundError struct { baseError @@ -165,6 +171,13 @@ func BuildError(response *http.Response, fault *Fault) error { buffer.String(), }, } + } else if response.StatusCode == 409 { + return &ConflictError{ + baseError{ + response.StatusCode, + buffer.String(), + }, + } } }