コード例 #1
0
 private void FaultCompleteFailure(CodedException error)
 {
     Host.Dispatcher.InvokeIfNecessary(
         PlatformDispatcher.AsyncOperationAlwaysValid,
         () => ReportError(
             PwmControlModelErrorString,
             null,
             MessageDescriptor.Empty,
             error.ResolvedErrorMessage));
 }
コード例 #2
0
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext == null)
            {
                throw new ArgumentNullException("actionExecutedContext");
            }
            HttpRequestMessage request   = actionExecutedContext.Request;
            CodedException     exception = actionExecutedContext.Exception as CodedException;

            if (exception == null)
            {
                actionExecutedContext.Response = request.CreateErrorResponse(HttpStatusCode.InternalServerError, actionExecutedContext.Exception);
            }
            else
            {
                actionExecutedContext.Response = request.CreateErrorResponse(exception.StatusCode, exception);
            }
        }
コード例 #3
0
 private void setErrorMessage(ActionExecutedContext filterContext, ErrorData viewModel)
 {
     if (String.IsNullOrWhiteSpace(ErrorMessage))
     {
         CodedException exception = filterContext.Exception as CodedException;
         if (exception == null)
         {
             viewModel.ErrorMessage = "An error occurred while processing your request.";
         }
         else
         {
             viewModel.ErrorMessage = filterContext.Exception.Message;
         }
     }
     else
     {
         viewModel.ErrorMessage = ErrorMessage;
     }
 }
コード例 #4
0
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            CodedException exception = filterContext.Exception as CodedException;

            if (exception == null)
            {
                filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(exception.StatusCode, exception.Message);
            }
            filterContext.ExceptionHandled = true;
            base.OnException(filterContext);
        }
コード例 #5
0
        private static SenderDelegate CreateAjaxSender(AjaxObjectFactory ajaxObject)
        {
            return((url, payload, callback) =>
            {
                Log.Debug($"{nameof(CreateAjaxSender)}: Create ajax sender {url} {payload}");
                var opt = new TransportOptions();
                if (!payload.IsNullOrEmpty())
                {
                    opt.Headers = new Dictionary <string, string>
                    {
                        { "Content-type", "text/plain" }
                    }
                }
                ;
                var ajaxUrl = new Uri(url).AddPath("/xhr_send");
                var xo = ajaxObject("POST", ajaxUrl.OriginalString, payload, opt);
                xo.Once("finish", (sender, e) =>
                {
                    var status = (int)e[0];
                    Log.Debug($"{nameof(CreateAjaxSender)}: Finish {status}");
                    xo = null;
                    if (status != 200 && status != 204)
                    {
                        callback(new Exception($"http status {status}"));
                        return;
                    }

                    callback(null);
                });

                return () =>
                {
                    Log.Debug($"{nameof(CreateAjaxSender)}: Abort");
                    xo.Close();
                    xo = null;
                    var err = new CodedException("Aborted", 1000);
                    callback(err);
                };
            });
        }
コード例 #6
0
        /// <summary>
        /// Helper method to handle an exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="includeException">if set to <c>true</c> include the full exception.</param>
        /// <remarks>
        /// Setting <paramref name="includeException"/> to true can introduce a security vulnerability
        /// because an attacker can use it to gather information about the system.
        /// </remarks>
        public void HandleException(Exception exception, bool includeException)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            Log.Instance.HandleException(exception);
            CodedException ce = exception as CodedException;

            if (ce != null)
            {
                code    = ce.ErrorCode;
                message = ce.ErrorMessage;
            }
            else
            {
                code    = -1;
                message = exception.Message;
            }
            if (includeException)
            {
                fullException = exception.ToString();
            }
        }