-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add support for custom exceptions #106
Conversation
I think this can be solved more easily with inheritance: namespace Application\Exception;
use ZfrRest\Http\Exception\Client\NotFoundException;
class CustomerNotFound extends NotFoundException
{
} or namespace Application\Exception;
use ZfrRest\Http\Exception\HttpExceptionInterface;
class SomethingIsWrong implements HttpExceptionInterface
{
// My custom HTTP Error, e.g http://httpstatusdogs.com/420-enhance-your-calm
} |
This does not work with exceptions thrown by third-party modules or if you throw exceptions from a third-party module (for instance if you throw UnauthorizedException from ZfcRbac). Even with your own exceptions, you may not want tie all your exceptions to ZfrRest. |
Hmm, having said that. The catch-all approach seems more reasonable to me. |
@@ -61,6 +61,14 @@ public function __construct($statusCode = null, $message = '', $errors = null) | |||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function setMessage($message) | |||
{ | |||
$this->message = $message; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast to (string)
I'm not really satisfied with it. The problem is that I really want this listener to catch all the exception so:
|
@bakura10 the default exception handler already sets a If we can avoid doing more work than needed, then it's ok |
Ok, I've updated. Looks merge able? |
@bakura10 looks ok, but my feedback on the code is still missing comments/patching |
Ok, merging for now then. |
Add support for custom exceptions
This PR brings support for custom exceptions, so that you can trigger custom exceptions in user land code, and map it to HTTP exception that can be interpreted by ZfrRest.
I'm wondering if we couldn't do another approach here, so that this listener is able to interpret ANY exceptions (even those not in the $exceptionMap). For those exception, it would create a generic ServerErrorException, with the message extracted from the exception. The reason is that we'd like to receive response from ZfrRest for any exception. If people forgot to add a specific exception they throw in ZfrRest, then this listener will do nothing. But I'm not sure.
ping @Ocramius