How to Retrieve Specific Error Details from Power Automate Workflow HTTP Response
I am currently using a Power Automate Workflow titled "Post to a channel when a webhook request is received." I've encountered an issue where large messages cause a "413 Entity Too Large" error. While I can see the error details on the Power Automate Workflow history page, I'm unable to retrieve this information directly from the HTTP response in my code. Instead, it returns only a "202 Accepted" response.
Here’s a snippet of the code I’m using to send the request:
using (HttpClient client = new HttpClient(handler)) {
if (teamsChannelSettings.TeamsWebHook != null)
{
client.BaseAddress = new Uri(teamsChannelSettings.TeamsWebHook);
}
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, string.Empty)
{
Content = new StringContent(adaptiveCardJsonString, Encoding.UTF8, "application/json")
};
HttpResponseMessage response = client.SendAsync(request).Result;
return response; }
Here is the response I get when the request is too large:
StatusCode: 202, ReasonPhrase: 'Accepted', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache x-ms-workflow-run-id: 08584804860707094154508038074CU195 x-ms-correlation-id: 447ddbe5-fc59-460a-84b6-21913634758e x-ms-client-tracking-id: 08584804860707094154508038074CU195 x-ms-trigger-history-name: 08584804860707094154508038074CU195 x-ms-execution-location: westeurope x-ms-workflow-system-id: /locations/westeurope/scaleunits/prod-14/workflows/25eb736c4dfe441983f6bdcdeb8628b7 x-ms-workflow-id: 25eb736c4dfe441983f6bdcdeb8628b7 x-ms-workflow-version: 08584805743398174085 x-ms-workflow-name: 396dce14-048f-44ed-af42-83c393f34330 x-ms-tracking-id: 447ddbe5-fc59-460a-84b6-21913634758e x-ms-ratelimit-burst-remaining-workflow-writes: 68 x-ms-ratelimit-remaining-workflow-download-contentsize: 49556480 x-ms-ratelimit-remaining-workflow-upload-contentsize: 49492340 x-ms-ratelimit-time-remaining-directapirequests: 4615247 x-ms-request-id: westeurope:447ddbe5-fc59-460a-84b6-21913634758e Strict-Transport-Security: max-age=31536000; includeSubDomains Cache-Control: no-cache Date: Tue, 16 Jul 2024 09:06:54 GMT Content-Length: 0 Expires: -1 }
We are receiving the same response for various failure cases, such as when the Adaptive Card JSON format is incorrect. Therefore, I need to determine the specific reason for the failure in the response. So that I can shrink the message in case of 413 EntityTooLarge
issue
How can I programmatically retrieve detailed error information, such as "413 Entity Too Large" or JSON format errors, directly from the HTTP response? Any guidance on capturing and handling such errors would be greatly appreciated.