Hi! This is the first gist-post about a new feature on one of Respect components.
Let's say you're crazy and designed a Hello World API that throws errors randomly. Definitely most APIs could be classified as such:
<?php
$router = new Respect\Rest\Router;
$router->any('/**', function() {
if (rand(0,1)) {
return 'Hello World';
} else {
throw new RuntimeException('Gotcha!');
}
});
Now you can catch those errors! Courtersy of Exception Routes:
<?php
$router->exceptionRoute('RuntimeException', function($e) {
return 'Caught a Gotcha!';
});
Hope you enjoy that. Also, there is something more:
These one is for catching PHP errors (Notices, Warnings, User Errors):
<?php
$router->errorRoute(function($err) {
return 'This errors happened: '.var_dump($err);
});
Hope you like it! =D Available now on PEAR and Composer. http://github.com/Respect/Rest