Remora / Remora.Rest

Reusable tooling for interacting with JSON-driven REST APIs
GNU Lesser General Public License v3.0
7 stars 10 forks source link

UnpackResponseAsync fails to get content of a 400 error correctly #26

Open b-rad15 opened 9 months ago

b-rad15 commented 9 months ago

Copied from https://github.com/Remora/Remora.Discord/issues/326

Description

When unpacking a 400 response from a webhook send I noticed that it was returning a simple HttpResultError (Code=400, Reason=Bad Request) despite the response containing content that explains the error in detail. Reading the response content using ReadAsStringAsync via the debugger correctly lets the library create the error object

Steps to Reproduce

Result<IMessage?> webhookResult = await _webhookApi.ExecuteWebhookAsync(<webhook id>, <webhook token>, content: "test", allowedMentions: new AllowedMentions(Parse: new[] { MentionType.Users }, Users: new Snowflake[] { new(0)) })); //This is code I had that triggered the bug

Expected Behavior

The response given in postman is {"allowed_mentions": ["parse:[\"users\"] and users: [ids...] are mutually exclusive."]}. This should resolve to a RestResultError when the content is read by UnpackResponseAsync. In UnpackResonseAsync at like line ~654 of HttpRestClient, response.Content.Headers.ContentLength should be a positive integer but is instead null unless read manually in the debugger

Current Behavior

The error in the result is simply an HttpResultError

Library / Runtime Information

net8.0 Remora.Discord 2024.1.0