1
0
mirror of https://github.com/bitwarden/server synced 2026-01-02 00:23:40 +00:00

fix(auth-validator): [PM-22975] Client Version Validator - Trying to fix the error occuring in the build process.

This commit is contained in:
Patrick Pimentel
2025-11-24 15:10:46 -05:00
parent d69842d668
commit 1681703eea

View File

@@ -225,7 +225,37 @@ public static class AssertHelper
public async static Task<T> AssertResponseTypeIs<T>(HttpContext context)
{
return await JsonSerializer.DeserializeAsync<T>(context.Response.Body);
try
{
if (context.Response.Body.CanSeek)
{
context.Response.Body.Position = 0;
}
return await JsonSerializer.DeserializeAsync<T>(context.Response.Body);
}
catch (JsonException ex)
{
string bodyText = "";
try
{
if (context.Response.Body.CanSeek)
{
context.Response.Body.Position = 0;
}
using var sr = new StreamReader(context.Response.Body, leaveOpen: true);
bodyText = await sr.ReadToEndAsync();
}
catch
{
// ignore read errors
}
throw new Xunit.Sdk.XunitException(
$"Failed to deserialize response to {typeof(T).Name}. " +
$"StatusCode: {context.Response.StatusCode}. Body:\n{bodyText}\nException: {ex}");
}
}
public static TimeSpan AssertRecent(DateTime dateTime, int skewSeconds = 2)