-
Notifications
You must be signed in to change notification settings - Fork 110
convert out of range exception to http exception #60
convert out of range exception to http exception #60
Conversation
do you plan to merge it? If so I close this PR and a change locally in a project. In case you ok to merge it let'me know what is left. |
Are you gonna merge it? if not we find another way to solve this problem in the project code. You can just leave few words about PR. |
<3 |
any news? |
This would be a BC break, and it also does not allow for your own business logic to do other tasks based on this specific exception. Thanks for the contribution though :-) |
yeah I agree. We could avoid BC breaks. For example the listener could not be enabled(I enabled it in my project code) or I can make it configurable at bundle extension level. It will be disabled by default so any BC breaks.
that's not really true. Cuz it is easy to add a listener with a higher priority and do what ever you want. I really think this logic should be inside the bundle. Without the listener it a bit broken. For example I copied the link If it is not provided by the bundle I would have to copy\past that listener from one project to another. This is what I and my friends already do. |
I think if you're able to make the change configurable (and disabled by default as you suggested, I'd be more inclined to include it. Could you adjust accordingly? |
@richsage sure, I would do it next days |
Thanks :-) |
@richsage updated. |
@@ -42,6 +42,13 @@ Add the WhiteOctoberPagerfantaBundle to your application kernel: | |||
); | |||
} | |||
|
|||
That's would also be good to set these options to true: |
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.
This needs a bit more explanation of what the configuration options actually do.
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.
@richsage done, please review
@makasim what about option for doing redirects to the 1st/last page? |
@Koc that's a good idea indeed but implementation could be tricky. The route could be defined by a developer and be very custom. |
We can use all current matched route and get parameters and replace only page number in one of them. |
@Koc sounds good |
@richsage done, please review |
It looks nice, a couple of suggestions:
|
yes it is a good idea, though it could blow the PR since we have to setup test env and staff like that. in any case we would try to add some tests.
sounds as a good idea. let'd do this |
There is already a kernel (https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle/tree/master/TestsProject/app), but I think we would need to tests both cases (converting and not converting, so different configuration). This could be done maybe through environments? |
@pablodip maybe we can pass (somehow) an config as array to |
@@ -57,6 +57,14 @@ | |||
<tag name="twig.extension" /> | |||
<argument type="service" id="service_container" /> | |||
</service> | |||
|
|||
<service id="pagerfanta.convert_not_valid_max_per_page_to_not_found_listener" class="WhiteOctober\PagerfantaBundle\EventListener\ConvertNotValidMaxPerPageToNotFoundListener"> |
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.
What about adding public=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.
no, listeners should be public since they lazy loaded,
starting from symfony 2.4 it throw exception with a warning that listener must be public
the plan is to introduce next concept(this one would allow to extend it with what @Koc proposed later): white_october_pagerfanta:
exceptional_cases:
page_out_of_range: none|404
page_invalid: none|404
# ... and listener: <?php
class ConvertExceptionalCaseTo404Listner
{
public function setConvertPageOutOfRange($boolean);
public function setConvertPageInvalid($boolean);
// ...
} and in the DI extnesion: <?php
if ($config['white_october_pagerfanta']['exceptionnal_cases']['page_out_of_range'] == '404') {
$listenerDefenition->addMethodCall('setConvertPageOutOfRange', array(true));
} |
|
@pablodip this is for cases when page is not a number. |
@pablodip there are lots of exceptions which start from |
I would personally specify the exceptions:
By the way, why is it difficult to implement the redirection? It would be something similar to what we already do when paginating, no?
Something like this seems nice, but it's up to you as you're implementing it! ;) |
Out range exception to http not found
@pablodip done, please review |
testOutOfRangeException() and testWrongMaxPerPageException() |
it could be solved by injecting a logger service. for that we would need a monolog bundle setuped and configured. I dont think its a good idea "just to hide a message". |
->arrayNode('exceptions_strategy') | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->scalarNode('out_of_range_page')->defaultValue(self::EXCEPTION_STRATEGY_NONE)->end() |
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.
default to false
or none
?
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.
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.
Ok, sorry, my fault, I didn't see that! ;)
It seems ok for me. I have the suggestions I've told you, but they're suggestions for names or how to get the exceptions when testing. I's also make unit tests for the events. Anyway I'm willing to merge. So just let me know if you wanna do some of the suggestions or prefer to merge like this ;) |
@pablodip yeap, we address your suggestions tomorrow. let's wait till than, thanks for the review |
Nice, thanks! ;) |
@pablodip done for tests names but we decided to keep action as is. It is a functional test so it would be good to test all things at once. |
…p-not-found convert out of range exception to http exception
Thanks! ;) |
I found that useful to convert
OutOfRangeCurrentPageException
toNotFoundHttpException
.For example a user can change the page number in the url, he will get 500 page before now it would 404 which is more descriptive.