in reply to Re: Reacting to Mojo::UserAgent Errors
in thread Reacting to Mojo::UserAgent Errors
Perhaps they have wised to me, but at 5 URL/s they don't seem to have taken offence. It would be nice if Mojo::UserAgent allowed the useragent details to be set, but that doesn't appear to be the case.
I have read from the book of Mojolicious at the temple of CPAN and the code you cite but I can't get it to work (or not work). I haven't found specific details so I interpret the if tree to be "look for 200" (aka is_success is a 200 response code), if not look for a connection problem (aka is_error means the GET timesout for some reason).
Specifically, if I run
use Mojo::UserAgent; # Fine grained response handling (dies on connection errors) my $ua = Mojo::UserAgent->new; my $res = $ua->get('mojoliciousness.org/perldoc')->result; if ($res->is_success) { print $res->body } elsif ($res->is_error) { print $res->message } elsif ($res->code == 301) { print $res->headers->location } else { print 'Whatever...' } print "Got to the end\n";
with the correct URL, it works correctly and spits out the perldoc page and the extra message. Nowif I misspell the URL, like I have above, I'll get a "Can't connect: No such host is known" message but it doesn't show the "Got to the end" message i.e. the script terminates at is_error and I can't recover and move on.
Am I missing something here?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Reacting to Mojo::UserAgent Errors
by marto (Cardinal) on Apr 17, 2018 at 03:42 UTC | |
Re^3: Reacting to Mojo::UserAgent Errors
by rizzo (Curate) on Apr 17, 2018 at 21:59 UTC | |
by AlwaysSurprised (Novice) on Apr 18, 2018 at 15:06 UTC |