public void OnException(ExceptionContext context) { if (context.Exception is RuleException) { var ruleEx = context.Exception as RuleException; var rule = ruleEx.Rule ?? new BrokenRule(); if (string.IsNullOrWhiteSpace(rule.Message)) { rule.Message = ruleEx.Message; } context.Result = new ObjectResult(ruleEx.Rule) { StatusCode = 400, DeclaredType = typeof(BrokenRule) }; } else { var response = new GenericErrorResult { Message = context.Exception.Message, StackTrace = context.Exception.StackTrace }; context.Result = new ObjectResult(response) { StatusCode = 500, DeclaredType = typeof(GenericErrorResult) }; } }
public static MaybeResult <T, GenericErrorResult> Failure <T>(GenericErrorResult error) { return(MaybeResult <T, GenericErrorResult> .CreateError(error)); }