Business-Payr
view release on metacpan or search on metacpan
lib/Business/Payr/Request.pm view on Meta::CPAN
unless ref $res_content eq 'HASH';
return $res_content
if $res->is_success;
# --- Error handling ---
# Payr has several documented error response formats, try each in turn.
# Authentication / authorisation errors:
# { "detail": "Invalid token." }
# { "detail": "Authentication credentials were not provided." }
if ( my $detail = $res_content->{detail} ) {
croak( "Payr $method $url returned $code: $detail" );
}
# Processing errors:
# { "error": "Failed to download agreement document from provided URL" }
if ( my $error = $res_content->{error} ) {
croak( "Payr $method $url returned $code: $error" );
}
t/business/payr/request.t view on Meta::CPAN
type => 'application/json',
);
throws_ok(
sub { $Request->api_post( '/onboarding/', {} ) },
qr/Payr POST .* returned 401: Invalid token\./,
'401 with detail key throws a meaningful error'
);
};
subtest 'authentication error - credentials not provided' => sub {
%status = (
code => 401,
body => '{"detail":"Authentication credentials were not provided."}',
type => 'application/json',
);
throws_ok(
sub { $Request->api_post( '/onboarding/', {} ) },
qr/Payr POST .* returned 401: Authentication credentials were not provided\./,
'401 missing credentials throws a meaningful error'
);
};
subtest 'processing error - error key' => sub {
%status = (
code => 400,
body => '{"error":"Failed to download agreement document from provided URL"}',
type => 'application/json',
);
( run in 0.761 second using v1.01-cache-2.11-cpan-007c89162af )