CollectionManager.GetAllScopesAsync throws on success


CollectionManager.GetAllScopesAsync is throwing exceptions on successful responses.

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
    // } ... 

// 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!

Hi @Brent_Farmer

Thanks for reporting, I created a ticket for tracking: NCBC-3072. This should be in the next release, but may be pushed out a release to February 2022. Feel free to push a PR if inclined and we’ll get it merged.

Happy Holidays,

Correction: This is only an issue for CollectionManager.GetAllScopesAsync.


Thanks, the fix will be in 3.2.6.