Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed Mojo::UserAgent to remove codes from parser errors
  • Loading branch information
kraih committed Nov 19, 2012
1 parent 45ff266 commit 1974984
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Improved documentation.
- Improved tests.
- Fixed state bugs in Mojo::Content::MultiPart.
- Fixed Mojo::UserAgent to remove codes from parser errors.

3.57 2012-11-12
- Deprecated Mojo::Exception->raw_message.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Message.pm
Expand Up @@ -577,7 +577,7 @@ before the entire message body has been received.
$msg = $msg->error('Parser error');
$msg = $msg->error('Parser error', 500);
Parser errors and codes.
Error and code.
=head2 C<extract_start_line>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction.pm
Expand Up @@ -224,7 +224,7 @@ Connection identifier or socket.
my $err = $tx->error;
my ($err, $code) = $tx->error;
Parser errors and codes.
Error and code.
=head2 C<is_finished>
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -303,9 +303,12 @@ sub _error {
sub _finish {
my ($self, $tx, $cb, $close) = @_;

# Common errors
# Remove code
my $res = $tx->res;
unless ($res->error) {
if (my $err = $res->error) { $res->error($err) }

# Common errors
else {

# Premature connection close
if ($close && !$res->code) { $res->error('Premature connection close') }
Expand Down
15 changes: 15 additions & 0 deletions t/mojo/user_agent.t
Expand Up @@ -312,6 +312,21 @@ $tx = $ua->get('/timeout?timeout=5');
ok !$tx->success, 'not successful';
is $tx->error, 'Inactivity timeout', 'right error';

# GET /echo (with message size limit)
{
local $ENV{MOJO_MAX_MESSAGE_SIZE} = 12;
my $tx = $ua->get('/echo' => 'Hello World!');
ok !$tx->success, 'not successful';
is(($tx->error)[0], 'Maximum message size exceeded', 'right error');
is(($tx->error)[1], undef, 'no code');
}

# GET /does_not_exist (404 response)
$tx = $ua->get('/does_not_exist');
ok !$tx->success, 'not successful';
is(($tx->error)[0], 'Not Found', 'right error');
is(($tx->error)[1], 404, 'right code');

# GET / (introspect)
my $req = my $res = '';
my $start = $ua->on(
Expand Down

0 comments on commit 1974984

Please sign in to comment.