Bug 28803: (follow-up) Error details improvement
This patch updates the exceptions thrown by Koha::Email to include the parameter that failed email validation and then updates the failure code to include this parameter and finally display this field in the template. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
a9b364a588
commit
c7d981df4e
|
|
@ -1417,13 +1417,23 @@ sub _send_message_by_email {
|
|||
);
|
||||
}
|
||||
catch {
|
||||
_set_message_status(
|
||||
{
|
||||
message_id => $message->{'message_id'},
|
||||
status => 'failed',
|
||||
failure_code => 'INVALID_EMAIL'
|
||||
}
|
||||
);
|
||||
if ( ref($_) eq 'Koha::Exceptions::BadParameter' ) {
|
||||
_set_message_status(
|
||||
{
|
||||
message_id => $message->{'message_id'},
|
||||
status => 'failed',
|
||||
failure_code => "INVALID_EMAIL:".$_->parameter
|
||||
}
|
||||
);
|
||||
} else {
|
||||
_set_message_status(
|
||||
{
|
||||
message_id => $message->{'message_id'},
|
||||
status => 'failed',
|
||||
failure_code => 'UNKNOWN_ERROR'
|
||||
}
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
return unless $email;
|
||||
|
|
|
|||
|
|
@ -77,8 +77,10 @@ sub create {
|
|||
|
||||
my $args = {};
|
||||
$args->{from} = $params->{from} || C4::Context->preference('KohaAdminEmailAddress');
|
||||
Koha::Exceptions::BadParameter->throw("Invalid 'from' parameter: ".$args->{from})
|
||||
unless Koha::Email->is_valid($args->{from}); # from is mandatory
|
||||
Koha::Exceptions::BadParameter->throw(
|
||||
error => "Invalid 'from' parameter: " . $args->{from},
|
||||
parameter => 'from'
|
||||
) unless Koha::Email->is_valid( $args->{from} ); # from is mandatory
|
||||
|
||||
$args->{subject} = $params->{subject} // '';
|
||||
|
||||
|
|
@ -89,8 +91,10 @@ sub create {
|
|||
$args->{to} = $params->{to};
|
||||
}
|
||||
|
||||
Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to})
|
||||
unless Koha::Email->is_valid($args->{to}); # to is mandatory
|
||||
Koha::Exceptions::BadParameter->throw(
|
||||
error => "Invalid 'to' parameter: " . $args->{to},
|
||||
parameter => 'to'
|
||||
) unless Koha::Email->is_valid( $args->{to} ); # to is mandatory
|
||||
|
||||
my $addresses = {};
|
||||
$addresses->{reply_to} = $params->{reply_to};
|
||||
|
|
@ -110,9 +114,11 @@ sub create {
|
|||
|
||||
foreach my $address ( keys %{$addresses} ) {
|
||||
Koha::Exceptions::BadParameter->throw(
|
||||
"Invalid '$address' parameter: " . $addresses->{$address} )
|
||||
error => "Invalid '$address' parameter: " . $addresses->{$address},
|
||||
parameter => $address
|
||||
)
|
||||
if $addresses->{$address}
|
||||
and !Koha::Email->is_valid($addresses->{$address});
|
||||
and !Koha::Email->is_valid( $addresses->{$address} );
|
||||
}
|
||||
|
||||
$args->{cc} = $addresses->{cc}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@
|
|||
[% IF ( QUEUED_MESSAGE.failure_code ) %]
|
||||
[% IF ( QUEUED_MESSAGE.failure_code == "INVALID_BORNUMBER" ) %]Invalid borrowernumber [% borrowernumber | html %]
|
||||
[% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_EMAIL' ) %]Unable to find an email address for this borrower
|
||||
[% ELSIF ( QUEUED_MESSAGE.failure_code == "INVALID_EMAIL" ) %]Invalid email address found [% borrowernumber | html %]
|
||||
[% ELSIF (matches = QUEUED_MESSAGE.failure_code.match('INVALID_EMAIL:(\w+)') ) %]Invalid [% matches.0 | html %] email address found [% borrowernumber | html %]
|
||||
[% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_FROM' ) %]Missing from email address
|
||||
[% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]Missing SMS number
|
||||
[% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]Message is duplicate
|
||||
|
|
|
|||
|
|
@ -996,16 +996,16 @@ subtest 'Test message_id parameter for SendQueuedMessages' => sub {
|
|||
'borrowernumber' => $borrowernumber,
|
||||
'to_address' => 'to@example.org',
|
||||
'message_transport_type' => 'email',
|
||||
'from_address' => 'root@localhost.' # invalid KohaAdminEmailAddress
|
||||
'from_address' => '@example.com' # invalid from_address
|
||||
};
|
||||
my $message_id = C4::Letters::EnqueueLetter($my_message);
|
||||
my $processed = C4::Letters::SendQueuedMessages( { message_id => $message_id } );
|
||||
is( $processed, 1, 'Processed 1 message when one message_id passed' );
|
||||
my $message_1 = C4::Letters::GetMessage($message_id);
|
||||
is( $message_1->{status}, 'failed', 'Invalid KohaAdminEmailAddress => status failed' );
|
||||
is( $message_1->{failure_code}, 'INVALID_EMAIL', 'Failure code set correctly for invalid email parameter');
|
||||
is( $message_1->{status}, 'failed', 'Invalid from_address => status failed' );
|
||||
is( $message_1->{failure_code}, 'INVALID_EMAIL:from', 'Failure code set correctly for invalid email parameter');
|
||||
|
||||
$my_message->{from_address} = 'root@example.org'; # valid KohaAdminEmailAddress
|
||||
$my_message->{from_address} = 'root@example.org'; # valid from_address
|
||||
$message_id = C4::Letters::EnqueueLetter($my_message);
|
||||
warning_like { C4::Letters::SendQueuedMessages( { message_id => $message_id } ); }
|
||||
qr|Fake send_or_die|,
|
||||
|
|
@ -1013,5 +1013,5 @@ subtest 'Test message_id parameter for SendQueuedMessages' => sub {
|
|||
$message_1 = C4::Letters::GetMessage($message_1->{message_id});
|
||||
my $message_2 = C4::Letters::GetMessage($message_id);
|
||||
is( $message_1->{status}, 'failed', 'Message 1 status is unchanged' );
|
||||
is( $message_2->{status}, 'sent', 'Valid KohaAdminEmailAddress => status sent' );
|
||||
is( $message_2->{status}, 'sent', 'Valid from_address => status sent' );
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue