Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs not displayed #636

Closed
Seotoolsdeveloper opened this issue Feb 25, 2023 · 11 comments
Closed

Bugs not displayed #636

Seotoolsdeveloper opened this issue Feb 25, 2023 · 11 comments

Comments

@Seotoolsdeveloper
Copy link

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

@DeveloperMarius
Copy link
Contributor

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

@Seotoolsdeveloper
Copy link
Author

Seotoolsdeveloper commented Feb 25, 2023

"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.

@skipperbent
Copy link
Owner

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

@Seotoolsdeveloper
Copy link
Author

I used the ExceptionHandler from it

@skipperbent
Copy link
Owner

skipperbent commented Feb 25, 2023

I used the ExceptionHandler from it

Did you register it in your routes.php file?

@Seotoolsdeveloper
Copy link
Author

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');
});`

@skipperbent
Copy link
Owner

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

@Seotoolsdeveloper
Copy link
Author

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

@skipperbent
Copy link
Owner

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?

@skipperbent
Copy link
Owner

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

@Seotoolsdeveloper
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants