You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2015/09/10 16:56:12 UTC

Redirect on exception

Hi,

How can I set a redirect when an exception has been thrown?

I tried the following:

     @Match("RequestExceptionHandler")
     public static RequestExceptionHandler 
decorateRequestExceptionHandler(final Response response) {
         return new RequestExceptionHandler() {

             @Override
             public void handleRequestException(Throwable exception) 
throws IOException {
                 response.sendRedirect("http://www.google.be");
             }

         };
     }

But this seems to only work for non-XHR requests? Or did I forget 
something here?

Nathan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect on exception

Posted by Ido Dovrat <id...@5oosh.com>.
The method you're decorating internally commits the response in case of an
XHR request. By the time your code runs the response can no longer be
modified.

[image: 5oosh_LOGO_FINAL_web-02]

*Ido Dovrat | CEO*

*T*: +972-77-5517453  *M*: +972-54-4264831

*F*: +972-77-5517454  *A*: 5 Kinneret St, Bnei Brak 5126237, Israel

On Thu, Sep 10, 2015 at 5:56 PM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:

> Hi,
>
> How can I set a redirect when an exception has been thrown?
>
> I tried the following:
>
>     @Match("RequestExceptionHandler")
>     public static RequestExceptionHandler
> decorateRequestExceptionHandler(final Response response) {
>         return new RequestExceptionHandler() {
>
>             @Override
>             public void handleRequestException(Throwable exception) throws
> IOException {
>                 response.sendRedirect("http://www.google.be");
>             }
>
>         };
>     }
>
> But this seems to only work for non-XHR requests? Or did I forget
> something here?
>
> Nathan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Also when I follow this pages instructions: 
https://tapestry.apache.org/error-page-recipe.html
It is not showing my custom error page... but still the default 
exception report from Tapestry.

I did exactly as described. My application runs in development mode and 
uses maven jetty plugin (version 8+).

What can be the problem here?

On 10/09/15 16:56, Nathan Quirynen wrote:
> Hi,
>
> How can I set a redirect when an exception has been thrown?
>
> I tried the following:
>
>     @Match("RequestExceptionHandler")
>     public static RequestExceptionHandler 
> decorateRequestExceptionHandler(final Response response) {
>         return new RequestExceptionHandler() {
>
>             @Override
>             public void handleRequestException(Throwable exception) 
> throws IOException {
>                 response.sendRedirect("http://www.google.be");
>             }
>
>         };
>     }
>
> But this seems to only work for non-XHR requests? Or did I forget 
> something here?
>
> Nathan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Anything else you think might be interfering? As I can't find anything 
wrong or don't know how to test if it is being used.

Nathan

On 11/09/15 14:28, Nathan Quirynen wrote:
> Yes I think the module is loaded as I can see in the logs :
>
> [INFO] ioc.RegistryBuilder Adding module definition for class 
> org.tynamo.exceptionpage.services.ExceptionPageModule
>
> On 10/09/15 20:53, Kalle Korhonen wrote:
>> On Thu, Sep 10, 2015 at 9:41 AM, Nathan Quirynen <
>> nathan@pensionarchitects.be> wrote:
>>
>>> Ok so I added the library by adding this in my pom.xml:
>>> |<dependency> <groupId>org.tynamo</groupId>
>>> <artifactId>tapestry-exceptionpage</artifactId> 
>>> <version>0.1.2</version>
>>> </dependency>|
>>> Then added following in my AppModule:
>>>      public void 
>>> contributeExceptionHandler(MappedConfiguration<Class<?>,
>>> Class<?>> configuration) {
>>>          configuration.add(Exception.class, Error.class);
>>>      }
>>> So I just added "throw new RuntimeException()" somewhere in a page 
>>> to test
>>> it, but it is not going to the error page, still tapestry its default
>>> exception reporting.
>>> Anything else I have to configure?
>>
>> No, that should be it. Are you sure the module is loaded ? You could use
>> @SubModule to make sure.
>>
>> Kalle
>>
>>
>>
>>> On 10/09/15 18:19, Kalle Korhonen wrote:
>>>
>>>> On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
>>>> nathan@pensionarchitects.be> wrote:
>>>>
>>>> I'm still on 5.3.7. Can't update to 5.4 yet sadly.
>>>>> Any options for 5.3.7?
>>>>>
>>>> You can get the same functionality as an external module:
>>>> http://www.tynamo.org/tapestry-exceptionpage+guide/
>>>>
>>>> Kalle
>>>>
>>>>
>>>>
>>>>> On 10/09/15 17:45, Kalle Korhonen wrote:
>>>>>
>>>>> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
>>>>>> nathan@pensionarchitects.be> wrote:
>>>>>>
>>>>>> How can I set a redirect when an exception has been thrown?
>>>>>>
>>>>>>> But this seems to only work for non-XHR requests? Or did I forget
>>>>>>> something here?
>>>>>>>
>>>>>>> If you are on T5.4, you can simply contribute an exception type ->
>>>>>>> error
>>>>>>>
>>>>>> page map to the DefaultRequestExceptionHandler. It handles XHR 
>>>>>> requests
>>>>>> as
>>>>>> well. See
>>>>>>
>>>>>>
>>>>>> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html 
>>>>>>
>>>>>> .
>>>>>>
>>>>>> Kalle
>>>>>>
>>>>>>
>>>>>> --------------------------------------------------------------------- 
>>>>>>
>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>
>>>>>
>>>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Yes I think the module is loaded as I can see in the logs :

[INFO] ioc.RegistryBuilder Adding module definition for class 
org.tynamo.exceptionpage.services.ExceptionPageModule

On 10/09/15 20:53, Kalle Korhonen wrote:
> On Thu, Sep 10, 2015 at 9:41 AM, Nathan Quirynen <
> nathan@pensionarchitects.be> wrote:
>
>> Ok so I added the library by adding this in my pom.xml:
>> |<dependency> <groupId>org.tynamo</groupId>
>> <artifactId>tapestry-exceptionpage</artifactId> <version>0.1.2</version>
>> </dependency>|
>> Then added following in my AppModule:
>>      public void contributeExceptionHandler(MappedConfiguration<Class<?>,
>> Class<?>> configuration) {
>>          configuration.add(Exception.class, Error.class);
>>      }
>> So I just added "throw new RuntimeException()" somewhere in a page to test
>> it, but it is not going to the error page, still tapestry its default
>> exception reporting.
>> Anything else I have to configure?
>
> No, that should be it. Are you sure the module is loaded ? You could use
> @SubModule to make sure.
>
> Kalle
>
>
>
>> On 10/09/15 18:19, Kalle Korhonen wrote:
>>
>>> On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
>>> nathan@pensionarchitects.be> wrote:
>>>
>>> I'm still on 5.3.7. Can't update to 5.4 yet sadly.
>>>> Any options for 5.3.7?
>>>>
>>> You can get the same functionality as an external module:
>>> http://www.tynamo.org/tapestry-exceptionpage+guide/
>>>
>>> Kalle
>>>
>>>
>>>
>>>> On 10/09/15 17:45, Kalle Korhonen wrote:
>>>>
>>>> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
>>>>> nathan@pensionarchitects.be> wrote:
>>>>>
>>>>> How can I set a redirect when an exception has been thrown?
>>>>>
>>>>>> But this seems to only work for non-XHR requests? Or did I forget
>>>>>> something here?
>>>>>>
>>>>>> If you are on T5.4, you can simply contribute an exception type ->
>>>>>> error
>>>>>>
>>>>> page map to the DefaultRequestExceptionHandler. It handles XHR requests
>>>>> as
>>>>> well. See
>>>>>
>>>>>
>>>>> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
>>>>> .
>>>>>
>>>>> Kalle
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect on exception

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Sep 10, 2015 at 9:41 AM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:

> Ok so I added the library by adding this in my pom.xml:
> |<dependency> <groupId>org.tynamo</groupId>
> <artifactId>tapestry-exceptionpage</artifactId> <version>0.1.2</version>
> </dependency>|
> Then added following in my AppModule:
>     public void contributeExceptionHandler(MappedConfiguration<Class<?>,
> Class<?>> configuration) {
>         configuration.add(Exception.class, Error.class);
>     }
> So I just added "throw new RuntimeException()" somewhere in a page to test
> it, but it is not going to the error page, still tapestry its default
> exception reporting.
> Anything else I have to configure?


No, that should be it. Are you sure the module is loaded ? You could use
@SubModule to make sure.

Kalle



> On 10/09/15 18:19, Kalle Korhonen wrote:
>
>> On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
>> nathan@pensionarchitects.be> wrote:
>>
>> I'm still on 5.3.7. Can't update to 5.4 yet sadly.
>>> Any options for 5.3.7?
>>>
>>
>> You can get the same functionality as an external module:
>> http://www.tynamo.org/tapestry-exceptionpage+guide/
>>
>> Kalle
>>
>>
>>
>>> On 10/09/15 17:45, Kalle Korhonen wrote:
>>>
>>> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
>>>> nathan@pensionarchitects.be> wrote:
>>>>
>>>> How can I set a redirect when an exception has been thrown?
>>>>
>>>>> But this seems to only work for non-XHR requests? Or did I forget
>>>>> something here?
>>>>>
>>>>> If you are on T5.4, you can simply contribute an exception type ->
>>>>> error
>>>>>
>>>> page map to the DefaultRequestExceptionHandler. It handles XHR requests
>>>> as
>>>> well. See
>>>>
>>>>
>>>> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
>>>> .
>>>>
>>>> Kalle
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>

Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Ok so I added the library by adding this in my pom.xml:

|<dependency> <groupId>org.tynamo</groupId> 
<artifactId>tapestry-exceptionpage</artifactId> <version>0.1.2</version> 
</dependency>|


Then added following in my AppModule:

     public void 
contributeExceptionHandler(MappedConfiguration<Class<?>, Class<?>> 
configuration) {
         configuration.add(Exception.class, Error.class);
     }

So I just added "throw new RuntimeException()" somewhere in a page to 
test it, but it is not going to the error page, still tapestry its 
default exception reporting.
Anything else I have to configure?

Nathan


On 10/09/15 18:19, Kalle Korhonen wrote:
> On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
> nathan@pensionarchitects.be> wrote:
>
>> I'm still on 5.3.7. Can't update to 5.4 yet sadly.
>> Any options for 5.3.7?
>
> You can get the same functionality as an external module:
> http://www.tynamo.org/tapestry-exceptionpage+guide/
>
> Kalle
>
>
>>
>> On 10/09/15 17:45, Kalle Korhonen wrote:
>>
>>> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
>>> nathan@pensionarchitects.be> wrote:
>>>
>>> How can I set a redirect when an exception has been thrown?
>>>> But this seems to only work for non-XHR requests? Or did I forget
>>>> something here?
>>>>
>>>> If you are on T5.4, you can simply contribute an exception type -> error
>>> page map to the DefaultRequestExceptionHandler. It handles XHR requests as
>>> well. See
>>>
>>> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
>>> .
>>>
>>> Kalle
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>


Re: Redirect on exception

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:

> I'm still on 5.3.7. Can't update to 5.4 yet sadly.
> Any options for 5.3.7?


You can get the same functionality as an external module:
http://www.tynamo.org/tapestry-exceptionpage+guide/

Kalle


>
>
> On 10/09/15 17:45, Kalle Korhonen wrote:
>
>> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
>> nathan@pensionarchitects.be> wrote:
>>
>> How can I set a redirect when an exception has been thrown?
>>> But this seems to only work for non-XHR requests? Or did I forget
>>> something here?
>>>
>>> If you are on T5.4, you can simply contribute an exception type -> error
>> page map to the DefaultRequestExceptionHandler. It handles XHR requests as
>> well. See
>>
>> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
>> .
>>
>> Kalle
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
I'm still on 5.3.7. Can't update to 5.4 yet sadly.

Any options for 5.3.7?

On 10/09/15 17:45, Kalle Korhonen wrote:
> On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
> nathan@pensionarchitects.be> wrote:
>
>> How can I set a redirect when an exception has been thrown?
>> But this seems to only work for non-XHR requests? Or did I forget
>> something here?
>>
> If you are on T5.4, you can simply contribute an exception type -> error
> page map to the DefaultRequestExceptionHandler. It handles XHR requests as
> well. See
> http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
> .
>
> Kalle
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Redirect on exception

Posted by Kalle Korhonen <ka...@gmail.com>.
On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:

> How can I set a redirect when an exception has been thrown?
> But this seems to only work for non-XHR requests? Or did I forget
> something here?
>

If you are on T5.4, you can simply contribute an exception type -> error
page map to the DefaultRequestExceptionHandler. It handles XHR requests as
well. See
http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.html
.

Kalle

Re: Redirect on exception

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
When creating a page that implements ExceptionReporter it works for both 
XHR and non-XHR, but I don't want it to be a popup on XHR requests, I 
want it to redirect to this page.

On 10/09/15 16:56, Nathan Quirynen wrote:
> Hi,
>
> How can I set a redirect when an exception has been thrown?
>
> I tried the following:
>
>     @Match("RequestExceptionHandler")
>     public static RequestExceptionHandler 
> decorateRequestExceptionHandler(final Response response) {
>         return new RequestExceptionHandler() {
>
>             @Override
>             public void handleRequestException(Throwable exception) 
> throws IOException {
>                 response.sendRedirect("http://www.google.be");
>             }
>
>         };
>     }
>
> But this seems to only work for non-XHR requests? Or did I forget 
> something here?
>
> Nathan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org