skipperbent / simple-php-router

Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bugs not displayed

Seotoolsdeveloper opened this issue · comments

I am creating an mvc using this router .
I am not able to see any errors and the app breaking .
How Can I show them

Hello,

please provide your code so that we can help you.
What do you mean with errors? Errors with the router or errors in your app?

You can enable the debug mode of the router or use an exception handler.

~ Marius

"errors in your app" that is what I mean

This is my exception

`<?php
namespace App\Handlers;

use Pecee\Http\Request;
use Pecee\SimpleRouter\Exceptions\NotFoundHttpException;
use Pecee\SimpleRouter\Handlers\IExceptionHandler;

class HomeExceptionHandler implements IExceptionHandler
{
/**
* @param Request $request
* @param \Exception $error
* @throws \Exception
*/

public function handleError(Request $request, \Exception $error): void
{
    
	

	/* You can use the exception handler to format errors depending on the request and type. */
	//echo $request->getUrl();
	if ($request->getUrl()->contains('/api')) {

		print_r($error->getMessage());
        response()->json([
			'error' => $error->getMessage(),
			'code'  => $error->getCode(),
		]);


	}
	
    // InvalidArgumentException
    // MalformedUrlException
    // HttpException
    print_r($error->getMessage());

	
	/* The router will throw the NotFoundHttpException on 404 */
	if($error instanceof NotFoundHttpException) {

		/*
		 * Render your own custom 404-view, rewrite the request to another route,
		 * or simply return the $request object to ignore the error and continue on rendering the route.
		 *
		 * The code below will make the router render our page.notfound route.
		 */

		$request->setRewriteCallback('DefaultController@notFound');
		return;

	}

	if($error instanceof TokenMismatchException){
       print_r('Token expired');
    }

	  

		if(isset($_GET['debug']) || APP_DEBUG==TRUE){
			print_r($error);
		}
		
	throw $error;

}

}`

Its not printing the errors.

Are you using the demo project? Might not be completely up to date give me a moment and I'll update it

I used the ExceptionHandler from it

I used the ExceptionHandler from it

Did you register it in your routes.php file?

Yes. I have already done that

`Route::group(['prefix' => folderprefix,'exceptionHandler' => \App\Handlers\HomeExceptionHandler::class, 'mergeExceptionHandlers' => false], function () {

    Route::post('/api/event', 'WebeventController@index');
    Route::get('/api/event', 'WebeventController@index');
});`

Do just get a blank page? Is there any information in php_errors.log?

no info
php_errors.log is not available either.
So I am not able to see any php general error.

I think the router is disabling it by the exception maybe

If no exception handler is present, the exception will just be thrown like normal.
Do you see any exceptions without the exception-handler enabled? Or is errors completely disabled in your setup?

Please try this project, I just updated it and confirmed it works.

Exception thrown when visiting /api/demo (GET)

https://github.com/skipperbent/simple-router-demo

Its now working correctly .
Thanks
The types :void and :?string were the issue