autorest: Return the body of HttpOperationExceptions (to view the detail)

Given I use an Azure Rest NuGet (e.g. Power BI) When an HttpOperationException occurs Then I want the body of the response

For example client.Datasets.DeleteDatasetByIdAsync("BAD", "Missing", "None");

Returns “Operation returned an invalid status code ‘Unauthorized’” but using Fiddler I can see there is a more detailed error.

62 {"error":{"code":"UnknownError","pbi.error":{"code":"UnknownError","parameters":{},"details":[]}}} 0

This is also true for other requests that are 404 / 500

image

This is not just for Power BI

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 16 (4 by maintainers)

Most upvoted comments

It would make sense to me to include common http information in an exception by default.

Eagerly awaiting for this to be in the roadmap (1.1?)

Looks like you can

 try
                    {
                        await client.Datasets.SetAllConnectionsAsync(_config.WorkspaceCollectionName, workspaceId,
                            dataSet.Id.ToString(),
                            new Dictionary<string, object> {{"connectionString", targetDatabase.ToConnectionString()}});
                    }
                    catch (Microsoft.Rest.HttpOperationException httpOperationException)
                    {
                        var phase = httpOperationException.Response.ReasonPhrase; 
//Bad Request
                        var content = httpOperationException.Response.Content; 
// {"error":{"code":"InvalidRequest","message":"Invalid dataset. This API can only be called on a DirectQuery dataset"}}
                        throw new  PowerBIException(content );
                    }