Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Error handling in Mojolicious

by Fletch (Bishop)
on Jul 08, 2021 at 19:05 UTC ( [id://11134812]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Error handling in Mojolicious
in thread Error handling in Mojolicious

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-10 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found