Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 2d0b7e3

Browse files
authored
Merge branch 'master' into f/org_id
2 parents a7ef268 + b8c854e commit 2d0b7e3

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Xero.Api/Infrastructure/OAuth/OAuthTokens.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ public IToken GetToken(string baseUri, IToken consumer, string endPoint, string
7777

7878
if (response.StatusCode != HttpStatusCode.OK)
7979
{
80-
throw new OAuthException(response.Body);
80+
if (response.Body.Contains("oauth_problem"))
81+
{
82+
throw new OAuthException(response.Body);
83+
}
84+
85+
throw new UnexpectedOauthResponseException(response.StatusCode, response.Body);
8186
}
8287

8388
var qs = HttpUtility.ParseQueryString(response.Body);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Net;
3+
4+
namespace Xero.Api.Infrastructure.OAuth
5+
{
6+
public class UnexpectedOauthResponseException : Exception
7+
{
8+
public HttpStatusCode ResponseStatusCode { get; set; }
9+
public string ResponseBody { get; set; }
10+
11+
public UnexpectedOauthResponseException(HttpStatusCode responseStatusCode, string responseBody) : base("An unexpected HTTP response was returned while performing OAuth operations")
12+
{
13+
ResponseStatusCode = responseStatusCode;
14+
ResponseBody = responseBody;
15+
}
16+
}
17+
}

Xero.Api/Xero.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
<Compile Include="Infrastructure\Interfaces\ITokenStore.cs" />
250250
<Compile Include="Infrastructure\Exceptions\XeroApiException.cs" />
251251
<Compile Include="Core\Endpoints\BrandingThemesEndpoint.cs" />
252+
<Compile Include="Infrastructure\OAuth\UnexpectedOauthResponseException.cs" />
252253
<Compile Include="Infrastructure\RateLimiter\IRateLimiter.cs" />
253254
<Compile Include="Infrastructure\RateLimiter\RateLimiter.cs" />
254255
<Compile Include="Infrastructure\ThirdParty\HttpUtility\UrlEncoder.cs" />

0 commit comments

Comments
 (0)