public void Handle(HttpStatusCode statusCode, NancyContext context) { var response = new Negotiator(context); Error error = null; if (context.Items.ContainsKey("OnErrorException")) { var exception = context.Items["OnErrorException"] as Exception; error = new Error { ErrorMessage = exception.Message, FullException = exception.ToString() }; } response.WithModel(new ErrorPageViewModel { Title = "Sorry, something went wrong", Summary = error == null ? "An unexpected error occurred." : error.ErrorMessage, Details = error == null ? null : error.FullException // TODO: Obey "ShowFullErrors" flag in config }).WithStatusCode(statusCode).WithView("Error"); var errorresponse = responseNegotiator.NegotiateResponse(response, context); string s = ""; context.Response = errorresponse; }
private static Negotiator GetNegotiator(object routeResult, NancyContext context) { var negotiator = routeResult as Negotiator; if (negotiator == null) { context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Wrapping result of type {0} in negotiator\n", routeResult.GetType())); negotiator = new Negotiator(context); negotiator.WithModel(routeResult); } return negotiator; }