JasperK's avatar

Custom HTTP Error Pages bugged?

Hi,

What else do I have to do to make the custom error-views work?

Docs:

Custom HTTP Error Pages Laravel makes it easy to return custom error pages for various HTTP status codes. For example, if you wish to customize the error page for 404 HTTP status codes, create a resources/views/errors/404.blade.php. This file will be served on all 404 errors generated by your application. The views within this directory should be named to match the HTTP status code they correspond to.

So I did this: https://www.dropbox.com/s/v34lmnz9ebt6ono/Schermafdruk%202015-09-17%2014.35.33.png?dl=0

But it isn't working. What else to do? It doesn't work on L5 and L5.1..

As you can see in the file: /Users/x/Code/foobar/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:

class Handler implements ExceptionHandlerContract
{
    /**
     * Render the given HttpException.
     *
     * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
     * @return \Symfony\Component\HttpFoundation\Response
     */
    protected function renderHttpException(HttpException $e)
    {
        $status = $e->getStatusCode();

        if (view()->exists("errors.{$status}")) {
            return response()->view("errors.{$status}", ['exception' => $e], $status);
        } else {
            return $this->convertExceptionToResponse($e);
        }
    }

Then a template with the name of 404.blade.php in the errors-folder in the app recourses folder should do the trick. But it doesn't do the trick.

0 likes
10 replies
JillzTom's avatar

The 404 Error pages should automatically load when you request for a route which doesn't exist. If somebody request for a resource which doesn't exit, call :

//This should show the 404 Error Page
abort(404);
JasperK's avatar

@pmall it keeps returning the default views. I wanna overwrite them like is mentioned in the docs. Cleared cache, compiles, dumps etc.

pmall's avatar

Not sure but it may work only in production env.

Also, can you show us for what kind of error you expect them to show up ?

JasperK's avatar

@pmall yes, only in PRD. I expect my view to be shown when I'm making a 404 or 500 response view. Just the view from /resources/views/404.blade.php or 500.blade.php

pmall's avatar

when I'm making a 404 or 500 response view

?

The exception handler render those views when there is an uncatched HttpException. For example when no route is matched or by using abort(404);.

lorvent's avatar
lorvent
Best Answer
Level 6

if you put them in resources/views/errors they shoud work ex: resources/views/errors/404.blade.php

OOPS: i find that you are doing it properly...may be some other package over-writing it...

in handler.php, try to return something above that view related code to see whether that part is getting executed or not.

Please or to participate in this conversation.