Exemple #1
0
        /// <summary>
        /// Based on the exception raised by the implementation class, assigns
        /// as response an instance of <see cref="ActorFault" />.
        /// </summary>
        /// <param name="context">The context for the action.</param>
        public override void OnException(HttpActionExecutedContext context)
        {
            #region Validations

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            #endregion

            var  request  = context.ActionContext.Request;
            bool detailed = ZincConfiguration.Current.Rest.Errors.Detailed;

            ActorFault fault;

            if (context.Exception is ActorException)
            {
                ActorException aex = (ActorException)context.Exception;
                fault = ActorFault.From(aex, detailed);
            }
            else
            {
                fault = ActorFault.FromUnhandled(context.Exception, detailed);
            }

            context.Response = request.CreateResponse <ActorFault>(HttpStatusCode.InternalServerError, fault);
        }
Exemple #2
0
        /// <summary>
        /// Handles the exception.
        /// </summary>
        /// <param name="context">
        /// Exception handling context.
        /// </param>
        /// <param name="cancellationToken">
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Task.
        /// </returns>
        public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
        {
            #region Validations

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            #endregion

            ActorFault fault;
            bool       detailed = ZincConfiguration.Current.Rest.Errors.Detailed;

            if (context.Exception is ActorException)
            {
                ActorException aex = (ActorException)context.Exception;
                fault = ActorFault.From(aex, detailed);
            }
            else
            {
                fault = ActorFault.FromUnhandled(context.Exception, detailed);
            }

            context.Result = new ExceptionResponse(fault);
            return(Task.CompletedTask);
        }
Exemple #3
0
        /// <summary>
        /// Serializes an instance of <see cref="ActorException" /> to XML.
        /// </summary>
        /// <param name="error">
        /// Exception.
        /// </param>
        /// <returns>
        /// XML representation of error.
        /// </returns>
        private static string ToXml(ActorException error)
        {
            if (error == null)
            {
                return(null);
            }

            var fault = ActorFault.From(error, true);

            return(ToXml(fault));
        }
Exemple #4
0
        /// <summary />
        public ExceptionResponse(ActorFault fault)
            : base()
        {
            if (fault == null)
            {
                throw new ArgumentNullException(nameof(fault));
            }

            this.StatusCode = HttpStatusCode.InternalServerError;
            this.Content    = new StringContent(JsonConvert.SerializeObject(fault));
            this.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        }