private void session_Error(object sender, ResponseErrorEventArgs e) { if (_context.UseDebugMode) { Console.WriteLine("\tSemantria executor got an error with {0} status code. The reason is: {1}", e.Status, e.Message); } AnalysisExecutionProgressEventArgs ea = new AnalysisExecutionProgressEventArgs(AnalysisExecutionStatus.Failed, 0, 0); ea.Reason = e.Message; _context.OnExecutionProgress("Semantria", ea); }
/// <summary> /// Triggers the <see cref="ResponseError"/>. /// </summary> /// <remarks>To insure that each event handler has a chance to process the event, any exception is suspended.</remarks> internal static void NotifyResponseError(ResponseErrorEventArgs e) { if (null != ResponseError) { var invocationList = ResponseError.GetInvocationList(); foreach (var invocation in invocationList) { try { var inv = invocation as EventHandler <ResponseErrorEventArgs>; inv(null, e); } catch { } } } }
/// <summary> /// Handles the response error event. /// </summary> private static void HandleResponseError(object sender, ResponseErrorEventArgs e) { foreach (var handler in ResponseErrorHandlers) { try { var errorCode = e.ErrorData.ErrorCode.ToString(); if (handler.ErrorCode == "*" || errorCode == handler.ErrorCode || Regex.IsMatch(errorCode, handler.ErrorCode, RegexOptions.IgnoreCase)) { var realHandler = Activator.CreateInstance(handler.Type) as IResponseErrorHandler; realHandler.Handle(e.ErrorData); e.IsHandled = true; } } catch { // Nothing to do. } } }
private void onPostRequestFailed(object sender, ResponseErrorEventArgs e) { submissionStatus.Text = LocalizedString.Get("Sorry! We weren't able to submit your request."); doneButton.Visible = true; }
private void onVersionRequestFailed(object sender, ResponseErrorEventArgs e) { SetUpdateStatus(UpdateStatusStates.UpToDate); }
/// <summary> /// Performs the HTTP request. /// </summary> /// <returns>The server response string(UTF8 decoded).</returns> public virtual string Request() { HttpWebRequest req = HttpWebRequest.Create(ConstructUri()) as HttpWebRequest; AppendHeaders(req.Headers); if (!string.IsNullOrEmpty(Method)) { req.Method = Method; } if (!string.IsNullOrEmpty(ContentType)) { req.ContentType = ContentType; } PrepareRequest(req); // Calls GetRequestStream with a "GET" method, an exception is thrown "Cannot send a content-body with this verb-type." if (req.Method == HttpMethod.Post) { using (var reqStream = req.GetRequestStream()) { WriteBody(reqStream); } // ContentLength is automatically calculated. } WebResponse resp = null; try { resp = req.GetResponse(); } catch (WebException wex) { ErrorResponse errorResp; var webResp = wex.Response as HttpWebResponse; if (null == webResp) { throw new AMicroblogException(LocalErrorCode.NetworkUnavailable); } try { var responseContent = RetrieveResponse(webResp); if (!string.IsNullOrEmpty(responseContent) && responseContent.StartsWith(Constants.JsonHeader, StringComparison.InvariantCultureIgnoreCase)) { errorResp = JsonSerializationHelper.JsonToObject <ErrorResponse>(responseContent); //TODO: 21327 token expired } else { // Handle other cases errorResp = new ErrorResponse() { ErrorCode = (int)webResp.StatusCode, ErrorMessage = webResp.StatusDescription }; } } catch (Exception exx) { throw new AMicroblogException(LocalErrorCode.ProcessResponseErrorHandlingFailed, exx); } var aex = new AMicroblogException(errorResp.ErrorMessage, wex) { IsRemoteError = true, ErrorCode = errorResp.ErrorCode }; var e = new ResponseErrorEventArgs(req.RequestUri.AbsoluteUri, aex, req.Method, req.ContentType); Environment.NotifyResponseError(e); aex.IsHandled = e.IsHandled; throw aex; } return(RetrieveResponse(resp)); }
void _engine_Error(object sender, ResponseErrorEventArgs ea) { SemantriaWorkerException workerException = new SemantriaWorkerException(ea.Message, ea.Status); ErrorOccurredCallback(this, workerException); }