app/Exceptions/Handler.php
/**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
Register the exception handling callbacks for the application.
@return void
Register the exception handling callbacks for the application . @return void
public function register()
    {
        $this->renderable(function (Throwable $e, $request) {
            if ($request->is('api/*')) {
                $type = get_class($e);
                switch ($type) {
                    case AuthenticationException::class:
                        $status_code = 401;
                        break;
                    case AccessDeniedHttpException::class:
                        $status_code = 403;
                        break;
                    case NotFoundHttpException::class:
                        $status_code = 404;
                        break;
                    default:
                        $status_code = 500;
                        break;
                }
                return response()->json(['success' => false, 'msg' => $e->getMessage() ?: last(explode('\\', $type)), 'data' => []], $status_code);
            }
            $this->report($e);
        });
    }
public function register ( ) { $ this -> renderable ( function ( Throwable $ e , $ request ) { if ( $ request -> is ( 'api/*' ) ) { $ type = get_class ( $ e ) ; switch ( $ type ) { case AuthenticationException :: class : $ status_code = 401 ; break ; case AccessDeniedHttpException :: class : $ status_code = 403 ; break ; case NotFoundHttpException :: class : $ status_code = 404 ; break ; default : $ status_code = 500 ; break ; } return response ( ) -> json ( [ 'success' => false , 'msg' => $ e -> getMessage ( ) ? : last ( explode ( '\\' , $ type ) ) , 'data' => [ ] ] , $ status_code ) ; } $ this -> report ( $ e ) ; } ) ; }
Register the exception handling callbacks for the application.
Register the exception handling callbacks for the application .
// return response()->json(['success' => false, 'msg' => $e->getMessage() ?: last(explode('\\', $type)), 'data' => $e->getTrace()], $status_code);