Beispiel #1
0
        protected virtual ExceptionResponse BuildResponseBody(Exception ex)
        {
            var res = new ExceptionResponse(ex.Message);

            if (ex is AggregateException aex)
            {
                _log.WriteVerbose("AggregateException detected, use InternalException to full up Message");
                res.Message = aex.InnerExceptions.FirstOrDefault()?.Message;
            }

            if (_isDetailsEnabled)
            {
                res.Details = ex.ToString();
            }

            return(res);
        }
Beispiel #2
0
 protected virtual async Task HandleResponse(IOwinContext context, int status, ExceptionResponse body)
 {
     context.Response.StatusCode = status;
     if (context.Response.Body.CanWrite)
     {
         context.Response.ContentType = "application/json";
         using (var writter = new StreamWriter(context.Response.Body))
         {
             await writter.WriteAsync(JsonConvert.SerializeObject(body, Formatting.None, new JsonSerializerSettings
             {
                 DefaultValueHandling  = DefaultValueHandling.Ignore,
                 MaxDepth              = 3,
                 NullValueHandling     = NullValueHandling.Ignore,
                 MissingMemberHandling = MissingMemberHandling.Ignore,
                 ContractResolver      = _contractResolver
             }));
         }
     }
     else
     {
         _log.WriteWarning("Response body is not writtable stream, error message dropped.");
     }
 }