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
This commit is contained in:
2026-02-07 11:42:11 -05:00
parent 210d18220b
commit d88ed64e37
2 changed files with 24 additions and 1 deletions

View File

@@ -1833,9 +1833,17 @@ public class JellyfinController : ControllerBase
// Forward to Jellyfin server with client headers // Forward to Jellyfin server with client headers
var (result, statusCode) = await _proxyService.PostJsonAsync("Users/AuthenticateByName", body, Request.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); _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) if (statusCode == 401)
{ {
return Unauthorized(new { error = "Invalid username or password" }); return Unauthorized(new { error = "Invalid username or password" });

View File

@@ -374,6 +374,21 @@ public class JellyfinProxyService
var errorContent = await response.Content.ReadAsStringAsync(); var errorContent = await response.Content.ReadAsStringAsync();
_logger.LogWarning("❌ SESSION: Jellyfin POST request failed: {StatusCode} for {Url}. Response: {Response}", _logger.LogWarning("❌ SESSION: Jellyfin POST request failed: {StatusCode} for {Url}. Response: {Response}",
response.StatusCode, url, errorContent); 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); return (null, statusCode);
} }