public void Handle(Nancy.HttpStatusCode statusCode, Nancy.NancyContext context)
        {
            if (context.Request.Headers.Accept.Count() == 0)
            {
                return;
            }

            if (context.Request.Headers.Accept.First().Item1.Contains("/json") ||
                context.Request.Headers.Accept.First().Item1.Contains("/xml"))
            {
                return;
            }

            // this is most probably XmlHttpRequest
            if (context.Request.Method == "PATCH" ||
                context.Request.Method == "DELETE")
            {
                return;
            }

            if (context.Request.Method == "GET" ||
                context.Request.Method == "POST" ||
                context.Request.Headers.UserAgent.Contains("Mozilla") ||
                context.Request.Headers.UserAgent.Contains("WebKit") ||
                context.Request.Headers.UserAgent.Contains("Trident"))
            {
                var response = _renderer.RenderView(context, "Codes/" + (int)statusCode);
                response.StatusCode  = statusCode;
                response.ContentType = "text/html; charset=utf-8";
                context.Response     = response;
            }
        }
示例#2
0
        public void Handle(Nancy.HttpStatusCode statusCode, NancyContext context)
        {
            var response = RenderView(context, "PageNotFound");

            response.StatusCode = HttpStatusCode.NotFound;
            context.Response    = response;
        }
示例#3
0
 public bool HandlesStatusCode(Nancy.HttpStatusCode statusCode, Nancy.NancyContext context)
 {
     return
         ((statusCode == HttpStatusCode.Forbidden) ||
          (statusCode == HttpStatusCode.NotFound) ||
          (statusCode == HttpStatusCode.InternalServerError) ||
          (statusCode == HttpStatusCode.Locked));
 }
示例#4
0
        public void Handle(Nancy.HttpStatusCode statusCode, Nancy.NancyContext context)
        {
            var response = viewRenderer.RenderView(context, "Error", new ErrorViewModel {
                Code = (int)statusCode
            });

            response.StatusCode = statusCode;
            context.Response    = response;
        }
        public void Handle(Nancy.HttpStatusCode statusCode, NancyContext context)
        {
            object errorObject;

            context.Items.TryGetValue(NancyEngine.ERROR_EXCEPTION, out errorObject);
            Exception error = (errorObject as Exception).GetBaseException();

            Console.WriteLine("Error occured: " + error.Message + ", " + error.StackTrace);
        }
示例#6
0
        public Nancy.Response MakeResponseString(WebServiceV2.DefaultResponse i, Nancy.HttpStatusCode code = Nancy.HttpStatusCode.OK)
        {
            var jsonString = JsonConvert.SerializeObject(i);
            var response   = (Nancy.Response)jsonString;

            response.ContentType = "application/json";
            response.StatusCode  = code;
            return(response);
        }
示例#7
0
        /*--------------------------------------------------------------------------------------------*/
        private Response GetResponse(ApiEntry pEntry)
        {
            IApiResponse   apiResp = pEntry.Function(NewReq());
            HttpStatusCode status  = (HttpStatusCode)(int)apiResp.Status;
            var            cookies = new List <INancyCookie>();

            foreach (Cookie c in apiResp.Cookies)
            {
                var nc = new NancyCookie(c.Name, c.Value, c.HttpOnly, c.Secure);
                nc.Domain  = c.Domain;
                nc.Expires = c.Expires;
                nc.Path    = c.Path;
                cookies.Add(nc);
            }

            ////

            if (apiResp.RedirectUrl != null)
            {
                var r = new RedirectResponse(apiResp.RedirectUrl);

                foreach (INancyCookie c in cookies)
                {
                    r.Cookies.Add(c);
                }

                return(r);
            }

            if (apiResp.Html != null)
            {
                byte[] bytes = Encoding.UTF8.GetBytes(apiResp.Html);
                return(new HtmlResponse(status, (s => s.Write(bytes, 0, bytes.Length)),
                                        apiResp.Headers, cookies));
            }

            var tr = new TextResponse(status, apiResp.Json, Encoding.UTF8, apiResp.Headers, cookies);

            tr.ContentType = "application/json";
            return(tr);
        }
示例#8
0
 public bool HandlesStatusCode(Nancy.HttpStatusCode statusCode, Nancy.NancyContext context)
 {
     return((int)statusCode >= 400);
 }
 public new void Handle(Nancy.HttpStatusCode statusCode, NancyContext context)
 {
     base.Handle(statusCode, context);
     NancyPipelineExtensions.AddCORSSupport(context);
 }
示例#10
0
 public Response CreateError(string message, HttpStatusCode code = HttpStatusCode.BadRequest) =>
 Response.AsJson(new { Success = false, Message = message }).WithStatusCode(code);
示例#11
0
        /// <summary>
        /// Creates the error response.
        /// </summary>
        /// <param name="setParameters">The set parameters action.</param>
        /// <param name="statusCode">The status code.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">setParameters could not be null</exception>
        protected Response CreateErrorResponse(Action <ErrorResponseBuilder> setParameters, Nancy.HttpStatusCode statusCode = Nancy.HttpStatusCode.BadRequest)
        {
            if (setParameters == null)
            {
                throw new ArgumentException("setParameters could not be null");
            }

            var builder = new ErrorResponseBuilder();

            setParameters(builder);

            return(Response.AsJson(builder.BuildResponse())
                   .WithStatusCode(statusCode));
        }
示例#12
0
 /// <summary>
 /// Creates the error response.
 /// </summary>
 /// <param name="statusCode">The status code.</param>
 /// <returns></returns>
 protected Response CreateErrorResponse(Nancy.HttpStatusCode statusCode)
 {
     return(Response.AsJson("{}")
            .WithStatusCode(statusCode));
 }
示例#13
0
 public bool HandlesStatusCode(Nancy.HttpStatusCode statusCode, NancyContext context)
 {
     return(statusCode == Nancy.HttpStatusCode.InternalServerError);
 }