Skip to content

Commit c635771

Browse files
authored
Merge pull request #650 from skipperbent/v5-fix-exception
[BUGFIX] Exception handling improvements
2 parents 8c79b74 + 791d69b commit c635771

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,17 @@ class CustomExceptionHandler implements IExceptionHandler
10361036
return;
10371037

10381038
}
1039+
1040+
/* Other error */
1041+
if($error instanceof MyCustomException) {
1042+
1043+
$request->setRewriteRoute(
1044+
// Add new route based on current url (minus query-string) and add custom parameters.
1045+
(new RouteUrl(url(null, null, []), 'PageController@error'))->setParameters(['exception' => $error])
1046+
);
1047+
return;
1048+
1049+
}
10391050

10401051
throw $error;
10411052

src/Pecee/SimpleRouter/Router.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function start(): ?string
346346
/* Verify csrf token for request */
347347
$this->csrfVerifier->handle($this->request);
348348
} catch(Exception $e) {
349-
$this->handleException($e);
349+
return $this->handleException($e);
350350
}
351351
}
352352

@@ -444,12 +444,12 @@ public function routeRequest(): ?string
444444
}
445445

446446
} catch (Exception $e) {
447-
$this->handleException($e);
447+
return $this->handleException($e);
448448
}
449449

450450
if ($methodNotAllowed === true) {
451451
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
452-
$this->handleException(new NotFoundHttpException($message, 403));
452+
return $this->handleException(new NotFoundHttpException($message, 403));
453453
}
454454

455455
if (count($this->request->getLoadedRoutes()) === 0) {

0 commit comments

Comments
 (0)