From 519d840b1937bf4d2b55950a86b462c8bc41e928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szak=C3=A1ts=20Alp=C3=A1r=20Zsolt?= Date: Tue, 12 Aug 2025 21:52:56 +0200 Subject: [PATCH] Handle deserialization error --- .../Services/TeslaAuthenticatorService.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/ProofOfConcept/Services/TeslaAuthenticatorService.cs b/Source/ProofOfConcept/Services/TeslaAuthenticatorService.cs index ed8b855..5038589 100644 --- a/Source/ProofOfConcept/Services/TeslaAuthenticatorService.cs +++ b/Source/ProofOfConcept/Services/TeslaAuthenticatorService.cs @@ -63,13 +63,20 @@ public class TeslaAuthenticatorService string json = await response.Content.ReadAsStringAsync(); // Deserialize - Token? result = JsonSerializer.Deserialize(json); + try + { + Token? result = JsonSerializer.Deserialize(json); - if (result is null) - throw new FormatException($"Could not deserialize token response: {json}"); - - // Return the token response - return result; + if (result is null) + throw new FormatException("Response could not be deserialized (null)."); + + // Return the token response + return result; + } + catch (Exception e) + { + throw new AggregateException($"Could not deserialize token response: {json}", e); + } } /// Retrieves a cached partner authentication token or acquires a new one if not available.