| 1 | package Net::ACME2::X::HTTP::Protocol; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Net::ACME2::X::HTTP::Protocol | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This exception class means that an error occurred with an HTTP | ||
| 12 | request, and the problem had specifically to do with something | ||
| 13 | that happened on the remote server, not just a general connection | ||
| 14 | problem. For example, this class would be suitable for use when | ||
| 15 | you get a 500 (Internal Server Error) or a 404 (Not Found), but it | ||
| 16 | would not be suitable for use if you get a Connection Refused TCP | ||
| 17 | error when trying to connect. | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | |||
| 24 | use parent qw( Net::ACME2::X::Generic ); | ||
| 25 | |||
| 26 | # In a normal HTTP response, we don't necessarily know if the body is going | ||
| 27 | # to be meaningful for display, so only include the first chunk. | ||
| 28 | # | ||
| 29 | #(accessed from tests) | ||
| 30 | use constant BODY_DISPLAY_SIZE => 1_024; | ||
| 31 | |||
| 32 | #named args required: | ||
| 33 | # | ||
| 34 | # method | ||
| 35 | # reason | ||
| 36 | # url | ||
| 37 | # status | ||
| 38 | # | ||
| 39 | sub new { | ||
| 40 | my ( $self, $args_hr ) = @_; | ||
| 41 | |||
| 42 | my $content = $args_hr->{'content'}; | ||
| 43 | if ( defined($content) && length($content) > BODY_DISPLAY_SIZE() ) { | ||
| 44 | substr( $content, BODY_DISPLAY_SIZE() ) = '…'; | ||
| 45 | } | ||
| 46 | |||
| 47 | $content ||= q<>; | ||
| 48 | |||
| 49 | return $self->SUPER::new( | ||
| 50 | "The response to the HTTP “$args_hr->{'method'}” request from “$args_hr->{'url'}” indicated an error ($args_hr->{'status'}, $args_hr->{'reason'}): “$content”", | ||
| 51 | $args_hr, | ||
| 52 | ); | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; |