react.js Replace img src onerror
This works best for me <img src={record.picture} onError={({ currentTarget }) => { currentTarget.onerror = null; // prevents looping currentTarget.src=”image_path_here”; }} />
This works best for me <img src={record.picture} onError={({ currentTarget }) => { currentTarget.onerror = null; // prevents looping currentTarget.src=”image_path_here”; }} />
Under your main views.py add your own custom implementation of the following two views, and just set up the templates 404.html and 500.html with what you want to display. With this solution, no custom code needs to be added to urls.py Here’s the code: from django.shortcuts import render_to_response from django.template import RequestContext def handler404(request, *args, … Read more
Your code is technically correct. If you looked at the headers of that blank page, you’d see a 404 header, and other computers/programs would be able to correctly identify the response as file not found. Of course, your users are still SOL. Normally, 404s are handled by the web server. User: Hey, do you have … Read more
The up-to-date answer (as of PHP 5.4 or newer) for generating 404 pages is to use http_response_code: <?php http_response_code(404); include(‘my_404.php’); // provide your own HTML for the error page die(); die() is not strictly necessary, but it makes sure that you don’t continue the normal execution.
In ASP.NET MVC 3 and above you can return a HttpNotFoundResult from the controller. return new HttpNotFoundResult(“optional description”);
If you are using PHP’s curl bindings, you can check the error code using curl_getinfo as such: $handle = curl_init($url); curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); /* Get the HTML or whatever is linked in $url. */ $response = curl_exec($handle); /* Check for 404 (file not found). */ $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); if($httpCode == 404) { /* Handle … Read more
I was experiencing this same symptom – 404 on woff files in Chrome – and was running an application on a Windows Server with IIS 6. If you are in the same situation you can fix it by doing the following: Solution 1 “Simply add the following MIME type declarations via IIS Manager (HTTP Headers … Read more
The code is taken from http://blogs.microsoft.co.il/blogs/shay/archive/2009/03/06/real-world-error-hadnling-in-asp-net-mvc-rc2.aspx and works in ASP.net MVC 1.0 as well Here’s how I handle http exceptions: protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); // Log the exception. ILogger logger = Container.Resolve<ILogger>(); logger.Error(exception); Response.Clear(); HttpException httpException = exception as HttpException; RouteData routeData = new RouteData(); routeData.Values.Add(“controller”, “Error”); if … Read more
Don’t render 404 yourself, there’s no reason to; Rails has this functionality built in already. If you want to show a 404 page, create a render_404 method (or not_found as I called it) in ApplicationController like this: def not_found raise ActionController::RoutingError.new(‘Not Found’) end Rails also handles AbstractController::ActionNotFound, and ActiveRecord::RecordNotFound the same way. This does two … Read more