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