Yes, indeed.
Sven
On 09.03.2016 15:43, Lars Törner wrote:
Hi Sven and thanks for your answer!
Ok I see! That's a better solution. I guess it means that I don't have to
set:
getExceptionSettings().setAjaxErrorHandlingStrategy(
AjaxErrorStrategy.INVOKE_FAILURE_HANDLER);
Because we'll never get to the DefaultExceptionMapper (in the case of an
expected unexpected exception).
Cheers
Lars
2016-03-09 10:56 GMT+01:00 Sven Meier <s...@meiers.net>:
Hi Lars,
if this is a good or bad way to handle exceptions during ajax requests
I'd keep your IRequestCycleListener and just return new
ErrorCodeRequestHandler(500, message) from there.
No need to fiddle with IExceptionMapper and/or DefaultExceptionMapper.
Have fun
Sven
On 09.03.2016 09:33, Lars Törner wrote:
About exception handling
I would like a fallback for unexcpected exceptions that are thrown during
ajax-calls.
I don't want to redirect to a new page so in my application#init I do:
getExceptionSettings().setAjaxErrorHandlingStrategy(AjaxErrorStrategy.INVOKE_FAILURE_HANDLER);
For the moment I have a request cycle listener for exceptions (added also
in application#init). Which implements #onException but for now does
nothing if an ajax-request is running:
!((WebRequest) requestCycle.getRequest()).isAjax()) -> return null
AjaxErrorStrategy.INVOKE_FAILURE_HANDLER leads to
org.apache.wicket.DefaultExceptionMapper.internalMap(Exception) returns
ErrorCodeRequestHandler(500)
What I would like is to register a global failure handler that via java
script shows a nice toaster with a user friendly message:
Wicket.Event.subscribe('/ajax/call/failure',
function (jqEvent, attributes, jqXHR, errorThrown, textStatus)
{
//TODO Show a fancy toaster with a nice localized user error message
});
ErrorCodeRequestHandler above has also a constructor that takes a message:
ErrorCodeRequestHandler(final int errorCode, final String message)
I guess this can be used to get the nice message to the browser?
So when I write this an do some more thinking my conclusion is that I must
implement my own IExceptionMapper (extending DefaultExceptionMapper?).
I will then create my new ExceptionMapper in MyApplication#init and
override Application#getExceptionMapperProvider() to return it. In my
exception mapper I can check all types of unexpected exeptions my
application might throw and get the corresponding user message to supply
it
to ErrorCodeRequestHandler(final int errorCode, final String message) and
then let failure handler show it in the toaster.
Ok, so now I guess it would be easier to just test this, but the mail is
written so I hope I don´t waste to much of your time by asking if this is
a
good or bad way to handle exceptions during ajax requests.
Cheers
Lasse
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org