internal static FacebookApiException GetRestException(object result)
{
// The REST API does not return a status that causes a WebException
// even when there is an error. For this reason we have to parse a
// successful response to see if it contains error information.
// If it does have an error message we throw a FacebookApiException.
FacebookApiException resultException = null;
if (result != null)
{
var resultDict = result as IDictionary<string, object>;
if (resultDict != null)
{
if (resultDict.ContainsKey("error_code"))
{
string error_code = resultDict["error_code"].ToString();
string error_msg = null;
if (resultDict.ContainsKey("error_msg"))
{
error_msg = resultDict["error_msg"] as string;
}
// Error Details: http://wiki.developers.facebook.com/index.php/Error_codes
if (error_code == "190")
{
resultException = new FacebookOAuthException(error_msg, error_code);
}
else if (error_code == "4" || error_code == "API_EC_TOO_MANY_CALLS" || (error_msg != null && error_msg.Contains("request limit reached")))
{
resultException = new FacebookApiLimitException(error_msg, error_code);
}
else
{
resultException = new FacebookApiException(error_msg, error_code);
}
}
}
}
return resultException;
}