From fee33ee3ff27c3c89ff8a27701242b62334f8e58 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 31 Mar 2025 09:30:02 +0200 Subject: Propagate more HTTP errors, sync error handling callback --- LibMatrix/Extensions/MatrixHttpClient.Single.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'LibMatrix/Extensions') diff --git a/LibMatrix/Extensions/MatrixHttpClient.Single.cs b/LibMatrix/Extensions/MatrixHttpClient.Single.cs index afbe52f..bfc3f3b 100644 --- a/LibMatrix/Extensions/MatrixHttpClient.Single.cs +++ b/LibMatrix/Extensions/MatrixHttpClient.Single.cs @@ -148,10 +148,10 @@ public class MatrixHttpClient { if (responseMessage.IsSuccessStatusCode) return responseMessage; //retry on gateway timeout - if (responseMessage.StatusCode == HttpStatusCode.GatewayTimeout) { - request.ResetSendStatus(); - return await SendAsync(request, cancellationToken); - } + // if (responseMessage.StatusCode == HttpStatusCode.GatewayTimeout) { + // request.ResetSendStatus(); + // return await SendAsync(request, cancellationToken); + // } //error handling var content = await responseMessage.Content.ReadAsStringAsync(cancellationToken); @@ -160,7 +160,12 @@ public class MatrixHttpClient { ErrorCode = "M_UNKNOWN", Error = "Unknown error, server returned no content" }; - if (!content.StartsWith('{')) throw new InvalidDataException("Encountered invalid data:\n" + content); + + // if (!content.StartsWith('{')) throw new InvalidDataException("Encountered invalid data:\n" + content); + if (!content.TrimStart().StartsWith('{')) { + responseMessage.EnsureSuccessStatusCode(); + throw new InvalidDataException("Encountered invalid data:\n" + content); + } //we have a matrix error MatrixException? ex; -- cgit 1.5.1