/// <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); }
/// <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); }