internal static void throwWebException(String apiUrl, WebException wex) { WebResponse response = wex.Response; using (Stream responseStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream)) { String error = reader.ReadToEnd(); String msg = "调用 API 失败: " + apiUrl + Environment.NewLine + "错误原因:" + error; logger.Error(msg); HttpClientException ex = new HttpClientException(msg); ex.ErrorInfo = error; throw ex; } } }
internal static void throwWebException( String apiUrl, WebException wex ) { WebResponse response = wex.Response; using (Stream responseStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader( responseStream )) { String error = reader.ReadToEnd(); String msg = "调用 API 失败: " + apiUrl + Environment.NewLine + "错误原因:" + error; logger.Error( msg ); HttpClientException ex = new HttpClientException( msg ); ex.ErrorInfo = error; throw ex; } } }
private void processEx( String content, HttpClientException ex ) { //{"error":"invalid_access_token","error_code":21332,"request":"/2/statuses/update.json"} //{"error":"expired_token","error_code":21327,"request":"/2/statuses/update.json"} // 原因不明,请查看已经记录的日志,此处不处理 if (ex.ErrorInfo == null) { return; } if (ex.ErrorInfo.IndexOf( "invalid_access_token" ) >= 0) { refreshToken(); republishPost( content ); return; } // token过期处理 if (ex.ErrorInfo.IndexOf( "expired_token" ) >= 0) { } }