コード例 #1
0
        private Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            string result = new APIError()
            {
                Message = exception.Message, StatusCode = (int)HttpStatusCode.InternalServerError
            }.ToString();

            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(context.Response.WriteAsync(result));
        }
コード例 #2
0
        private Task HandleExceptionAsync(HttpContext context, MyAPIException exception)
        {
            string result;

            context.Response.ContentType = "application/json";
            if (exception is MyAPIException)
            {
                result = new APIError()
                {
                    Message = exception.Message, StatusCode = (int)exception.StatusCode
                }.ToString();
                context.Response.StatusCode = (int)exception.StatusCode;
            }
            else
            {
                result = new APIError()
                {
                    Message = "Runtime Error", StatusCode = (int)HttpStatusCode.BadRequest
                }.ToString();
                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            return(context.Response.WriteAsync(result));
        }