public static ResponseExplanation From(Explanation explanation, bool isDebugEnabled) { if (explanation == null) { return(null); } var response = new ResponseExplanation { Message = explanation.Message, Type = GetRealTypeName(explanation.GetType()), DebugData = isDebugEnabled ? explanation.InternalMessage : null, Data = explanation.Data }; if (explanation.Details.Any()) { var details = new List <ResponseExplanation>(); foreach (var detail in explanation.Details) { details.Add(ResponseExplanation.From(detail, isDebugEnabled)); } response.Details = details; } return(response); }
public override Task ExecuteResultAsync(ActionContext context) { var requestIdProvider = context.HttpContext.RequestServices.GetService <IRequestIdProvider>(); var resultMapper = context.HttpContext.RequestServices.GetRequiredService <Policy.IPolicy>(); var options = context.HttpContext.RequestServices.GetRequiredService <IOptions <DomainOptions> >(); bool isDebugEnabled = options.Value.Debug; var requestId = (requestIdProvider == null) ? context.HttpContext.TraceIdentifier : requestIdProvider.RequestId; this.StatusCode = (int)resultMapper.GetStatusCode(this.maybe.Explanation); context.HttpContext.Response.Headers.Add("x-request-id", requestId); if (this.StatusCode != (int)HttpStatusCode.NoContent) { this.Value = new Response <T> { Content = this.maybe.HasValue ? this.maybe.Value : null, Status = new ReponseStatus { Code = this.StatusCode.Value, RequestId = requestId, Explanation = ResponseExplanation.From(this.maybe.Explanation, isDebugEnabled), } }; } return(base.ExecuteResultAsync(context)); }