Remora / Remora.Discord

A data-oriented C# Discord library, focused on high-performance concurrency and robust design.
GNU Lesser General Public License v3.0
246 stars 44 forks source link

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

Open b-rad15 opened 5 months ago

b-rad15 commented 5 months ago

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

b-rad15 commented 5 months ago

Since this appears to be solely a Remora.Rest issue to me on further investigation, I believe I've fixed it in https://github.com/Remora/Remora.Rest/pull/27