lundi 10 septembre 2018

How to display 500 error view with custom message?

I need to display messages depending on the type of exception in my own 'errors.500' view. I have done the following solution in Handler class, which so far works, but I'm afraid that this isn't quite right, because it converts server type exception into html type. May it cause any danger? What is the better approach?

public function render($request, Exception $exception)
{

    if ($exception instanceof FatalErrorException) {
        $exception = new HttpException(500, "Server error");
    }

    if ($exception instanceof ModelNotFoundException) {
       $exception = new HttpException(500, "Model not found");
    }

    if ($exception instanceof RelationNotFoundException) {
        $exception = new HttpException(500, "Relation not found");
    }
    return parent::render($request, $exception);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire