-
Notifications
You must be signed in to change notification settings - Fork 341
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
listen to other exceptions #748
Conversation
private static function isInternalException(UnexpectedValueException $exception): bool | ||
{ | ||
$messages = [ | ||
'/^Cannot filter by\: \[.+\] this field is not in allow list$/', | ||
'/^Cannot sort by\: \[.+\] this field is not in allow list\.$/', | ||
'/^Cannot sort with array parameter$/', | ||
'/^ODM query must be a FIND type query$/', | ||
'/^There is no component aliased by \[.+\] in the given Query$/', | ||
'/^There is no component field \[.+\] in the given Query$/', | ||
'/^There is no such field \[.+\] in the given Query component, aliased by \[.+\]$/', | ||
]; | ||
foreach ($messages as $regex) { | ||
if (preg_match($regex, $exception->getMessage()) > 0) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} |
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.
I'm usually not so fond of matching an exception by its message, especially if we control those exceptions.
Can't we create instead a custom exception (that's extending the UnexpectedValueException
) and catch that instead of matching the messages?
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.
I agree and I already opened an issue for that KnpLabs/knp-components#317
The problem is that we can only add the internal exception in a minor release of knp-components (e.g. 4.1.0) and so the fix in this bundle would stay for the users still using version 4.0.
My idea about the roadmap is:
- add the internal exception in the library, release a minor version of the library
- add support in the bundle for both (new internal exception and ugly old message-based exceptions), release a patch version of the bundle
- release a new minor version of the bundle, requiring library ^4.1 and removing the ugly old message-based exceptions
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.
Great! Sorry, I missed that issue.
Thank you!
Fix #747