Response ConvertToHttpResponse(NancyContext ctx, Exception err)
        {
            string contentType = ctx.Request.Headers.ContentType;

            IExceptionRepackager handler =
                _config.ErrorHandlers.FirstOrDefault(x => x.CanHandle(err, contentType));

            Response response = handler == null
                                    ? _config.DefaultExceptionRepackager.Repackage(err, ctx, contentType)
                                    : handler.Repackage(err, ctx, contentType);

            _config.ResponseAction(response);

            return(response);
        }
示例#2
0
 public RestExceptionConfiguration WithDefault(IExceptionRepackager handler)
 {
     DefaultExceptionRepackager = handler;
     return(this);
 }
示例#3
0
 public RestExceptionConfiguration WithRepackager(IExceptionRepackager handler)
 {
     ErrorHandlers.Add(handler);
     return(this);
 }