public static async Task Handler(HttpContext context)
        {
            context.Response.StatusCode  = 500;
            context.Response.ContentType = "application/json";


            var exceptionHandlerPathFeature =
                context.Features.Get <IExceptionHandlerPathFeature>();

            switch (exceptionHandlerPathFeature.Error)
            {
            case null:
                return;

            case SunViewException sunViewException:
                await context.Response.WriteAsync(SunJson.Serialize(sunViewException.ErrorView));

                break;

            default:
                ErrorView errorView = ErrorView.ServerError(exceptionHandlerPathFeature.Error);
                await context.Response.WriteAsync(SunJson.Serialize(errorView));

                break;
            }
        }
        public async Task Invoke(HttpContext context)
        {
            try
            {
                await next(context);
            }
            catch (SunViewException e)
            {
                logger.LogError(e.ToString());
                context.Response.StatusCode = 500;

                await context.Response.WriteAsync(SunJson.Serialize(e.ErrorView ?? ErrorView.ServerError()));
            }
            catch (Exception e)
            {
                logger.LogError(e.ToString());
                context.Response.StatusCode = 500;

                ErrorView errorView = ErrorView.ServerError(e);
                await context.Response.WriteAsync(SunJson.Serialize(errorView));
            }
        }
 public SunViewException(ErrorView errorView)
     : base(string.Join(",", errorView.Errors.Select(x =>
                                                     $"{x.Description} {x.Message}")))
 {
     ErrorView = errorView;
 }