From d88ed64e378c0d7502459aabbd86c81678fc1bfb Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Sat, 7 Feb 2026 11:42:11 -0500 Subject: [PATCH] fix: pass through Jellyfin error responses to client - Modified PostJsonAsync to return error response body as JSON when available - Updated AuthenticateByName to pass through Jellyfin's actual error response - Clients now see Jellyfin's real error messages instead of generic ones --- allstarr/Controllers/JellyfinController.cs | 10 +++++++++- .../Services/Jellyfin/JellyfinProxyService.cs | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index 1a3656a..276a118 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -1833,9 +1833,17 @@ public class JellyfinController : ControllerBase // Forward to Jellyfin server with client headers var (result, statusCode) = await _proxyService.PostJsonAsync("Users/AuthenticateByName", body, Request.Headers); - if (result == null) + if (statusCode != 200) { _logger.LogWarning("Authentication failed - status {StatusCode}", statusCode); + + // Pass through Jellyfin's error response if available + if (result != null) + { + return StatusCode(statusCode, result.RootElement.GetRawText()); + } + + // Fallback to generic error if no response body if (statusCode == 401) { return Unauthorized(new { error = "Invalid username or password" }); diff --git a/allstarr/Services/Jellyfin/JellyfinProxyService.cs b/allstarr/Services/Jellyfin/JellyfinProxyService.cs index 80e0846..f4c34b1 100644 --- a/allstarr/Services/Jellyfin/JellyfinProxyService.cs +++ b/allstarr/Services/Jellyfin/JellyfinProxyService.cs @@ -374,6 +374,21 @@ public class JellyfinProxyService var errorContent = await response.Content.ReadAsStringAsync(); _logger.LogWarning("❌ SESSION: Jellyfin POST request failed: {StatusCode} for {Url}. Response: {Response}", response.StatusCode, url, errorContent); + + // Try to parse error response as JSON to pass through to client + if (!string.IsNullOrWhiteSpace(errorContent)) + { + try + { + var errorDoc = JsonDocument.Parse(errorContent); + return (errorDoc, statusCode); + } + catch + { + // Not valid JSON, return null + } + } + return (null, statusCode); }