Throwing the exception leads to a response code "500" for the ajax request; 
since code 500 signals an error the "fail" handler for the ajax request 
get´s triggered.

That of course does not mean that the content returned from the mojo server 
is rendered in your page; it was an ajax request after all, so rendering 
any content in the browser would be the responsibility of your javascript 
code in myapp_fail.

By the way: blindly rendering the response from the server to your user 
imho does not make much sense: something unexpected may have gone wrong 
server side so you cannot be sure what kind of error you got and if it was 
one you triggered on purpose like in your code show above.

If you add "location.href='/exception';" in the myapp_fail function then 
this happens:
0) You make your ajax request to the server
1) the exception template is rendered because of your "throw" 
2) your server sends a code 500 response with the content from the 
exception template
3) your javascript library receives a response with a status code 
indicating a server side processing error and calls the fail handler
4) your ajax fail handler receives the rendered output of the exception 
template and does something with it (or not)
5) you modify  "location.href"
6) the browser now makes a regular (non-ajax) request to the new URL 
in location.href which happens to be "/exception"
7) your server receives the request
8) something goes wrong and the exception template is rendered because of 
some internal error
9) the browser receives the output and displays it

Of course the response your browser receives in step 9 is in no way 
connected to the exception you threw in step 0.

After step 7 I´m not completely sure what happens; apparently you did 
create a callback for the route "/exception" (at least I believe so, 
because of the "in /exception" debug log message) but I don´t think that 
there´s any automatic connection between a route of that name and the 
internal exeception handling template. 
That´s probably the reason why the server generates a "501 Not Implemented" 
response.

In the end I believe the problem is less with using mojolicious but more so 
with some lack of understanding how ajax works and about the statelessnes 
of HTTP.

Hope I could point you in the right direction
- heiko

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to