Skip to content

Commit a9da038

Browse files
committed
Show a proper error message when refresh failed.
1 parent bf5282e commit a9da038

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

RadarrAPI/Controllers/TraktController.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using RadarrAPI.Database;
77
using RadarrAPI.Database.Models;
88
using TraktApiSharp;
9+
using TraktApiSharp.Exceptions;
910

1011
namespace RadarrAPI.Controllers
1112
{
@@ -80,14 +81,25 @@ public async Task<IActionResult> TraktCallback([FromQuery(Name = "refresh")] str
8081
{
8182
return BadRequest("Invalid refresh code specified.");
8283
}
84+
85+
try
86+
{
87+
var traktAuth = await _trakt.OAuth.RefreshAuthorizationAsync(refresh, _trakt.ClientId, _trakt.ClientSecret, GetRedirectUri());
88+
if (!traktAuth.IsValid)
89+
{
90+
return BadRequest("Received trakt token was invalid.");
91+
}
8392

84-
var traktAuth = await _trakt.OAuth.RefreshAuthorizationAsync(refresh, _trakt.ClientId, _trakt.ClientSecret, GetRedirectUri());
85-
if (!traktAuth.IsValid)
93+
return Ok(traktAuth);
94+
}
95+
catch (TraktAuthenticationException e)
8696
{
87-
return BadRequest("Received trakt token was invalid.");
97+
return StatusCode(401, new
98+
{
99+
Message = "Invalid refresh token specified.",
100+
MessageTrakt = e.Message.Replace("\n", ", ")
101+
});
88102
}
89-
90-
return Ok(traktAuth);
91103
}
92104

93105
private string GetRedirectUri()

0 commit comments

Comments
 (0)