Skip to content

Commit

Permalink
fixed error handling examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 29, 2012
1 parent 7dbbada commit 48bfc90
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -579,8 +579,8 @@ before the entire message body has been received.
=head2 C<error>
my $msg = $msg->error;
my ($msg, $code) = $msg->error;
my $err = $msg->error;
my ($err, $code) = $msg->error;
$msg = $msg->error('Parser error');
$msg = $msg->error('Parser error', 500);
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Transaction.pm
Expand Up @@ -220,8 +220,8 @@ Connection identifier or socket.
=head2 C<error>
my $msg = $tx->error;
my ($msg, $code) = $tx->error;
my $err = $tx->error;
my ($err, $code) = $tx->error;
Parser errors and codes.
Expand Down Expand Up @@ -278,8 +278,8 @@ message in C<error>, 400 and 500 responses also a code.
# Sensible exception handling
if (my $res = $tx->success) { say $res->body }
else {
my ($msg, $code) = $tx->error;
say $code ? "$code response: $msg" : "Connection error: $msg";
my ($err, $code) = $tx->error;
say $code ? "$code response: $err" : "Connection error: $err";
}
Error messages can be accessed with the C<error> method of the transaction
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -529,8 +529,8 @@ Mojo::UserAgent - Non-blocking I/O HTTP and WebSocket user agent
my $tx = $ua->post_form('search.cpan.org/search' => {q => 'mojo'});
if (my $res = $tx->success) { say $res->body }
else {
my ($msg, $code) = $tx->error;
say $code ? "$code response: $msg" : "Connection error: $msg";
my ($err, $code) = $tx->error;
say $code ? "$code response: $err" : "Connection error: $err";
}
# Quick JSON API request with Basic authentication
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Command/get.pm
Expand Up @@ -123,9 +123,9 @@ sub run {
my $tx = $ua->start($ua->build_tx($method, $url, \%headers, $content));

# Error
my ($msg, $code) = $tx->error;
my ($err, $code) = $tx->error;
$url = encode 'UTF-8', $url;
warn qq{Problem loading URL "$url". ($msg)\n} if $msg && !$code;
warn qq{Problem loading URL "$url". ($err)\n} if $err && !$code;

# JSON Pointer
return unless $selector;
Expand Down
6 changes: 3 additions & 3 deletions lib/ojo.pm
Expand Up @@ -57,9 +57,9 @@ sub import {

sub _request {
my $tx = $UA->start(@_);
my ($msg, $code) = $tx->error;
warn qq/Problem loading URL "@{[$tx->req->url->to_abs]}". ($msg)\n/
if $msg && !$code;
my ($err, $code) = $tx->error;
warn qq/Problem loading URL "@{[$tx->req->url->to_abs]}". ($err)\n/
if $err && !$code;
return $tx->res;
}

Expand Down

0 comments on commit 48bfc90

Please sign in to comment.