Hello,
CollectionManager.GetAllScopesAsync
is throwing exceptions on successful responses.
Couchbase.NetClient 3.2.5.0
The problem is in CollectionManager.GetAllScopesAsync CollectionManager.cs
result.StatusCode
is not being checked after the call to httpClient.GetAsync
. This allows successful responses to fall through to the call to HttpResponseMessageExtensions.ThrowOnError
which throws unconditionally.
// file CollectionManager.cs
public async Task<IEnumerable<ScopeSpec>> GetAllScopesAsync(GetAllScopesOptions? options = null)
{
// ...
var result = await httpClient.GetAsync(uri, options.TokenValue).ConfigureAwait(false);
// MISSING
// if (result.StatusCode != HttpStatusCode.OK)
// { ...
var body = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
var ctx = new ManagementErrorContext
{
HttpStatus = result.StatusCode,
Message = body,
Statement = uri.ToString()
};
//Throw specific exception if a rate limiting exception is thrown.
result.ThrowIfRateLimitingError(body, ctx);
//Throw any other error cases
result.ThrowOnError(ctx);
// } ...
}
// file HttpResponseMessageExtensions.cs
public static class HttpResponseMessageExtensions
{
public static void ThrowOnError(this HttpResponseMessage msg, ManagementErrorContext ctx)
{
throw new CouchbaseException
{
Context = ctx
};
}
}
The same issue exists for BucketManager.UpdateBucketAsync
.
I was able to put in a temporary workaround by catching the exception, checking CouchbaseException.Context.HttpStatus
for HttpStatusCode.OK
and building the ScopeSpec collection from Context.Message directly. Horrible but it works.
Any thoughts about a better band-aid?
Thank you!