src/APIResponse.php
public function handleAndResponseException(\Exception $ex)
    {

        $response = '';
        switch (true) {
            case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
                $response = $this->respondNotFound('Record not found');
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
                $response = $this->respondNotFound("Not found");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
                $response = $this->respondForbidden("Access denied");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
                $response = $this->respondBadRequest("Bad request");
                break;
            case $ex instanceof BadMethodCallException:
                $response = $this->respondBadRequest("Bad method Call");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
                $response = $this->respondForbidden("Method not found");
                break;
            case $ex instanceof \Illuminate\Database\QueryException:
                $response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Auth\AuthenticationException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\ValidationException:
                $response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
                break;
            case $ex instanceof NotAcceptableHttpException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\UnauthorizedException:
                $response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
                break;
            case $ex instanceof \Exception:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
        }
        return $response;
    }
public function handleAndResponseException(\Exception $ex)
    {

        $response = '';
        switch (true) {
            case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
                $response = $this->respondNotFound('Record not found');
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
                $response = $this->respondNotFound("Not found");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
                $response = $this->respondForbidden("Access denied");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
                $response = $this->respondBadRequest("Bad request");
                break;
            case $ex instanceof BadMethodCallException:
                $response = $this->respondBadRequest("Bad method Call");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
                $response = $this->respondForbidden("Method not found");
                break;
            case $ex instanceof \Illuminate\Database\QueryException:
                $response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Auth\AuthenticationException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\ValidationException:
                $response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
                break;
            case $ex instanceof NotAcceptableHttpException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\UnauthorizedException:
                $response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
                break;
            case $ex instanceof \Exception:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
        }
        return $response;
    }
public function handleAndResponseException ( \ Exception $ ex ) { $ response = '' ; switch ( true ) { case $ ex instanceof \ Illuminate \ Database \ Eloquent \ ModelNotFoundException : $ response = $ this -> respondNotFound ( 'Record not found' ) ; break ; case $ ex instanceof \ Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException : $ response = $ this -> respondNotFound ( "Not found" ) ; break ; case $ ex instanceof \ Symfony \ Component \ HttpKernel \ Exception \ AccessDeniedHttpException : $ response = $ this -> respondForbidden ( "Access denied" ) ; break ; case $ ex instanceof \ Symfony \ Component \ HttpKernel \ Exception \ BadRequestHttpException : $ response = $ this -> respondBadRequest ( "Bad request" ) ; break ; case $ ex instanceof BadMethodCallException : $ response = $ this -> respondBadRequest ( "Bad method Call" ) ; break ; case $ ex instanceof \ Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException : $ response = $ this -> respondForbidden ( "Method not found" ) ; break ; case $ ex instanceof \ Illuminate \ Database \ QueryException : $ response = $ this -> respondValidationError ( "Some thing went wrong with your query" , [ $ ex -> getMessage ( ) ] ) ; break ; case $ ex instanceof \ Illuminate \ Http \ Exceptions \ HttpResponseException : $ response = $ this -> respondInternalError ( "Something went wrong with our system" , [ $ ex -> getMessage ( ) ] ) ; break ; case $ ex instanceof \ Illuminate \ Auth \ AuthenticationException : $ response = $ this -> respondUnauthorized ( "Unauthorized request" ) ; break ; case $ ex instanceof \ Illuminate \ Validation \ ValidationException : $ response = $ this -> respondValidationError ( "In valid request" , [ $ ex -> getMessage ( ) ] ) ; break ; case $ ex instanceof NotAcceptableHttpException : $ response = $ this -> respondUnauthorized ( "Unauthorized request" ) ; break ; case $ ex instanceof \ Illuminate \ Validation \ UnauthorizedException : $ response = $ this -> respondUnauthorized ( "Unauthorized request" , [ $ ex -> getMessage ( ) ] ) ; break ; case $ ex instanceof \ Exception : $ response = $ this -> respondInternalError ( "Something went wrong with our system" , [ $ ex -> getMessage ( ) ] ) ; break ; } return $ response ; }
handle all type of exceptions

@param \Exception $ex

@return mixed|string
handle all type of exceptions