http-status-code-404
Why does HttpWebRequest throw an exception instead returning HttpStatusCode.NotFound?
Ya this can be quite annoying when web pages use status codes heavily and not all of them are errors. Which can make processing the body quite a pain. Personally I use this extension method for getting the response. public static class HttpWebResponseExt { public static HttpWebResponse GetResponseNoException(this HttpWebRequest req) { try { return (HttpWebResponse)req.GetResponse(); … Read more
One location block for all Nginx error codes
error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 405 /error/405.html; error_page 500 501 502 503 504 /error/5xx.html; location ^~ /error/ { internal; root /var/www/default; } http://nginx.org/r/location http://nginx.org/r/error_page http://nginx.org/r/root
Access denied: 403 or 404?
Use 404 Not found. The 404 status code can also be used in 403 scenarios, when the server does not want to send back the reason why it is refusing to serve the request. A good example is when the server senses some kind of an attack, which might be a brute force attack. In … Read more
How do you return 404 when resource is not found in Django REST Framework
Simply way to do it, you can use raise Http404, here is your views.py from django.http import Http404 from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView from yourapp.models import Snippet from yourapp.serializer import SnippetSerializer class SnippetDetailView(APIView): def get_object(self, pk): try: return Snippet.objects.get(pk=pk) except Snippet.DoesNotExist: raise Http404 def get(self, request, pk, format=None): … Read more
Django staticfiles app help
I implore you to read the howto docs here: http://docs.djangoproject.com/en/dev/howto/static-files/ In short: STATIC_ROOT is only used if you call the collectstatic manangement command. It’s not needed to add the directory to the STATICFILES_DIRS setting to serve your static files! During development (when the automatic serving view is used) staticfiles will automatically look for static files … Read more
How to detect an error 404 in an iframe?
The status only lives in the response header. The 404 Page is handling an HTTP Status Code, which is only included in the server’s response sent to the browser, but not in the actual window and document objects of the DOM that javascript may access. This means that while you certainly can collect the status-code … Read more
IIS7 custom 404 not showing
answer was to use <httpErrors existingResponse=”Replace” errorMode=”Custom”> <remove statusCode=”404″ subStatusCode=”-1″ /> <error statusCode=”404″ prefixLanguageFilePath=”” path=”/pages/404.aspx?he” responseMode=”ExecuteURL” /> </httpErrors> and not to have any system.web customErrors this worked for both .aspx and non .aspx requests. bizarrely this combination did not come up in any of the blog posts and stackoverflow answers I had investigated, it was … Read more
How do I force redirect all 404’s (or every page, whether invalid or not) to the homepage?
Setting the error page to the home page like this error_page 404 /index.html; has a small problem, the status code of the home page will be “404 not found”, if you want to load the home page with a “200 ok” status code you should do it like this error_page 404 =200 /index.html; This will … Read more
flask: error_handler for blueprints
You can use Blueprint.app_errorhandler method like this: bp = Blueprint(‘errors’, __name__) @bp.app_errorhandler(404) def handle_404(err): return render_template(‘404.html’), 404 @bp.app_errorhandler(500) def handle_500(err): return render_template(‘500.html’), 500