The debug output which may help illustrate my confusion...  The one message 
labeled [error] was generated by the Mojo::Exception->throw call -- which 
seems to show that it tried to render the exception tempate... which didn't 
display maybe because it caused any internal system error?

[Tue Mar 22 14:58:32 2016] [info] Listening at "http://localhost:80";
Server available at http://localhost:80
[Tue Mar 22 14:59:05 2016] [debug] GET "/"
[Tue Mar 22 14:59:05 2016] [debug] Routing to a callback
[Tue Mar 22 14:59:08 2016] [debug] Rendering template "index.html.ep" from 
DATA section
[Tue Mar 22 14:59:08 2016] [debug] 200 OK (3.023809s, 0.331/s)
[Tue Mar 22 14:59:10 2016] [debug] POST "/price"
[Tue Mar 22 14:59:10 2016] [debug] Routing to a callback
[Tue Mar 22 14:59:12 2016] [error] Problem in /price route.  Could not get 
product page for item-ishp
[Tue Mar 22 14:59:12 2016] [debug] Rendering template 
"exception.development.html.ep" from DATA section
[Tue Mar 22 14:59:12 2016] [debug] 500 Internal Server Error (1.312753s, 
0.762/s)
[Tue Mar 22 14:59:13 2016] [debug] GET "/exception"
[Tue Mar 22 14:59:13 2016] [debug] Routing to a callback
[Tue Mar 22 14:59:13 2016] [debug] in /exception
[Tue Mar 22 14:59:13 2016] [debug] Rendering cached template 
"exception.development.html.ep" from DATA section
[Tue Mar 22 14:59:13 2016] [debug] 501 Not Implemented (0.010857s, 92.106/s)




On Tuesday, March 22, 2016 at 1:59:20 PM UTC-4, [email protected] wrote:
>
> This is the end of my first week with Mojo working solo on a simple 
> Mojo::Lite AJAX application. I'm mostly stuck on exception handling in AJAX 
> callbacks.
>
> Much appreciate any guidance, pointers, or examples of working design 
> patterns for exception handling with AJAX callbacks.  
>
> For example, in a "/price" callback, I have some code as follows.
>
>   my $dom = $c->ua->get($url)->res->dom;
>   
>   if (!defined($dom)) {
>   Mojo::Exception->throw('Problem in /price route.  Could not get product 
> page for item-' . $itemid);
>   }
>
> I have an exception.development.html.ep template in the __DATA__ section.
>
> The AJAX call looks like this...
>
> $.ajax( myapp_ajax ).always( myapp_always ).done( myapp_done 
> ).fail( myapp_fail );
>
>
>
> I'd like to have the Mojo::Exception result in the render and display of 
> the exception template which includes the exception message ( 
> $exception->message?).  I believe the Mojo::Exception->throw triggers the 
> .fail() method in the .ajax call.   If I include the line 
> location.href='/exception'; in the myapp_fail function (passed to the 
> .ajax .fail method), it looks like the exception template is rendered twice 
> (displayed once) and the exception message is lost.  Without the 
> location.href line, the debug output shows that the exception template is 
> rendered... but it's not actually displayed.
>
> I suspect I'm doing multiple things wrong.... Again, much appreciate 
> advice / pointers / working design patterns on how best to handle 
> exceptions?
>
> Clueless in NoVa...
>
>
>
>
>

-- 
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