Comments (8)
Atm for AJAX results an empty json object is returned, I could also return "nothing", wouldn't matter :)
What information would you need (except of the status code which is sent anyway)? Some friendly HTTP Status Code Message? The Exception message (which can also be logged in the application)?
from easyerrorhandlingmvc.
And what content types should be supported? Plain text, JSON, XML, ... ?
from easyerrorhandlingmvc.
Thanks, I couldn't find the code causing this!
I was expecting the same HTML response as a non-ajax request. This is important for using AJAX with the HTML5 History API, for example.
I'd suggest not looking at the IsAjaxRequest
method, perhaps respond to the Accepts
header? Perhaps return HTML by default, if the header allows. If the Accepts
header does not allow html/text
, try the same with plaintext, JSON and XML?
I can't think of a use case where you would want a JSON 404, surely the code 404 and the error message should be enough? In this case, I'd probably always return the HTML.
from easyerrorhandlingmvc.
Is the reason it returns nothing with AJAX requests for saving bandwidth?
In this case, maybe return HTML if the Accepts
header allows, otherwise return empty string.
from easyerrorhandlingmvc.
If this sounds like a sensible solution, I'll fork and pull request.
from easyerrorhandlingmvc.
Sounds legit, so:
Iterate through the headers
The first match sorted by quality parameter should win
If HTML, just return the ViewResult
If JSON / XML, return a simple object (HTTP Status Code, HTTP Message, Exception information**)
If there is no match, return an empty (or HTML) result? What does the HTTP specification says here :)
** If we want to return this information, we have to check IsCustomErrorEnabled so we do not expose sensible information in production mode.
from easyerrorhandlingmvc.
Sounds sensible. I'll take a look over the weekend, hopefully.
from easyerrorhandlingmvc.
The Controller now returns a JSON object with more information for AJAX requests:
string message = exception != null && !requestContext.HttpContext.IsCustomErrorEnabled ? exception.ToString() : string.Empty;
actionResult = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
httpStatusCode = renderedHttpStatusCode,
httpStatusMessage = renderedHttpStatusCode.ToString(),
message = message
}
};
Message is only set when custom errors are disabled.
You might add your support for other content types over the weekend though :)
from easyerrorhandlingmvc.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easyerrorhandlingmvc.