Added OnError event to MetaObjectLock (#1585)

* Added OnError event to MetaObjectLock

* Updated event name
This commit is contained in:
Tim McCurdy
2024-09-27 20:12:02 +01:00
committed by GitHub
parent 722f21c464
commit 541abb00bd

View File

@@ -9,6 +9,11 @@ namespace k8s.LeaderElection.ResourceLock
private readonly string identity;
private T metaObjCache;
/// <summary>
/// OnHttpError is called when there is a http operation error.
/// </summary>
public event Action<HttpOperationException> OnHttpError;
protected MetaObjectLock(IKubernetes client, string @namespace, string name, string identity)
{
this.client = client ?? throw new ArgumentNullException(nameof(client));
@@ -47,8 +52,9 @@ namespace k8s.LeaderElection.ResourceLock
Interlocked.Exchange(ref metaObjCache, createdObj);
return true;
}
catch (HttpOperationException)
catch (HttpOperationException e)
{
OnHttpError?.Invoke(e);
// ignore
}
@@ -79,8 +85,9 @@ namespace k8s.LeaderElection.ResourceLock
Interlocked.Exchange(ref metaObjCache, replacedObj);
return true;
}
catch (HttpOperationException)
catch (HttpOperationException e)
{
OnHttpError?.Invoke(e);
// ignore
}