Laravel-permission: best practive for capturing exceptions

Created on 3 Jan 2018  路  1Comment  路  Source: spatie/laravel-permission

When a user access a page they don't have access to an Spatie \ Permission \ Exceptions \ is thrown, is there a recommended way to handle these?

User does not have the right roles.

Ideally being able to redirect the user and a message would be useful.

Most helpful comment

Figured it out by adding my handling inside app/Exceptions/Handler.php

/**
 * Render an exception into an HTTP response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $exception
 * @return \Illuminate\Http\Response
 */
public function render($request, Exception $e)
{

    if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
        flash($e->getMessage(), 'danger');
        return back();
    }

    return parent::render($request, $e);
}

>All comments

Figured it out by adding my handling inside app/Exceptions/Handler.php

/**
 * Render an exception into an HTTP response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $exception
 * @return \Illuminate\Http\Response
 */
public function render($request, Exception $e)
{

    if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
        flash($e->getMessage(), 'danger');
        return back();
    }

    return parent::render($request, $e);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

notflip picture notflip  路  3Comments

ergonomicus picture ergonomicus  路  3Comments

wreighsantos picture wreighsantos  路  4Comments

tripex picture tripex  路  3Comments

devingray picture devingray  路  3Comments