Not to disparage Mojo (or marto :) but that's one of the places where I have qualms about its docs. Some of the Mojo samples aren't what you should be aiming at because lots of places they'll show just chaining call after call after call. While it shows how simple things can be with Mojo it's eliding how you'd probably want to do it in a "real" application (and I'm speaking theoretically with large grains of salt here as I've never really done much in anger with Mojo myself).

Taking your sample code (which was just the kind of thing I was trying to draw out :) I were I doing something like this in a production manner my inclination would be to put checking in the places that interface with the outside world.

my $log = Mojo::Log->new; ## Or use $app->log . . . my $orig_result = $ua->get( $url )->result; if( $orig_result->is_success ) { my $dom = $orig_result->dom; my $target = $dom->at( q{...} )->attr( q{src} ); if( $target ) { my $save_result = $ua->get( q{https:} . $target )->result; if( $save_result->is_success ) { $save_result->save_to( q{target.jpg} ); } else { $log->error( qq{Problem fetching target '$target': }, $save_result->code, q{ }, $save_result->message ); } } else { $log->error( qq{Unable to locate CSS target in '$url'} ); } } else { $log->error( qq{Problem fetching '$url': }, $orig_message->code, q{ }, $orig_result->message ) }

(Again, Mojo novice so I'm sure I may be corrected too.)

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^3: Error handling in Mojolicious by Fletch
in thread Error handling in Mojolicious by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.