Redirect on exception

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Redirect on exception

nquirynen
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

Ido Dovrat
In reply to this post by nquirynen
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.

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 <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

Kalle Korhonen-2
In reply to this post by nquirynen
On Thu, Sep 10, 2015 at 7:56 AM, Nathan Quirynen <
[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
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 <
> [hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
In reply to this post by nquirynen
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

Kalle Korhonen-2
In reply to this post by nquirynen
On Thu, Sep 10, 2015 at 8:47 AM, Nathan Quirynen <
[hidden email]> 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 <
>> [hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
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 <
> [hidden email]> 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 <
>>> [hidden email]> 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

Kalle Korhonen-2
On Thu, Sep 10, 2015 at 9:41 AM, Nathan Quirynen <
[hidden email]> 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 <
>> [hidden email]> 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 <
>>>> [hidden email]> 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: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
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 <
> [hidden email]> 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 <
>>> [hidden email]> 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 <
>>>>> [hidden email]> 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: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Redirect on exception

nquirynen
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 <
>> [hidden email]> 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 <
>>>> [hidden email]> 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 <
>>>>>> [hidden email]> 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: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>>>
>>>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]