Skip to content

Commit

Permalink
Do not raise CredentialsExpired on other errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jessenic committed Aug 29, 2013
1 parent e5b8fc2 commit 3b407a9
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions SparklrLib/SparklrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ private async Task<JSONRequestEventArgs<T>> requestJsonObjectAsync<T>(string pat
Response = null
};
}

bool error = false;
WebException exc;
try
{
HttpWebResponse streamResp = (HttpWebResponse)await streamReq.GetResponseAsync();
Expand Down Expand Up @@ -213,26 +214,57 @@ private async Task<JSONRequestEventArgs<T>> requestJsonObjectAsync<T>(string pat
}
catch (WebException ex)
{
if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Forbidden)
{
raiseCredentialsExpired();
}

error = true;
exc = ex;
}
catch (Exception ex)
{
return new JSONRequestEventArgs<T>()
{
IsSuccessful = false,
Error = ex,
Response = (HttpWebResponse)ex.Response
Error = ex
};
}
catch (Exception ex)
if (error)
{
if (((HttpWebResponse)exc.Response).StatusCode == HttpStatusCode.Forbidden)
{
using (StreamReader strReader = new StreamReader(exc.Response.GetResponseStream(), Encoding.UTF8))
{
string json = await strReader.ReadToEndAsync();

if (json == "")
{
raiseCredentialsExpired();

This comment has been minimized.

Copy link
@jessenic

jessenic Aug 29, 2013

Author Member

This fix closes issue #51

}
else
{
//TODO: Handle other errors here, for example not authorized to see user profile:

This comment has been minimized.

Copy link
@jessenic

jessenic Aug 29, 2013

Author Member

Issue #52 should be fixed somewhere around here

//{
// "error": true,
// "info": {
// "notFriends": true,
// "following": false
// }
//}
}
}
}

return new JSONRequestEventArgs<T>()
{
IsSuccessful = false,
Error = ex
Error = exc,
Response = (HttpWebResponse)exc.Response
};
}

return new JSONRequestEventArgs<T>()
{
IsSuccessful = false,
Error = null,
Response = null
};
}

public void ManualLogin(string authToken, long userId)
Expand Down

0 comments on commit 3b407a9

Please sign in to comment.