From 62ea61d8f8ba2878408de0e7154e55dac0eca112 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Wed, 27 Aug 2014 15:43:59 +0300 Subject: [PATCH] Bug 3186 - invalid or uninstalled SMSSendDriver (or bad number format) causes process_message_queue to fail This patch wraps the SMS::Send Driver initialization and sending process into an eval block and gracefully causes the sending to fail, instead of crashing the process and preventing emails and good sms' from being sent. --- C4/SMS.pm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/C4/SMS.pm b/C4/SMS.pm index 24580d6..0ec1fb3 100644 --- a/C4/SMS.pm +++ b/C4/SMS.pm @@ -75,19 +75,28 @@ sub send_sms { return unless $driver; # warn "using driver: $driver to send message to $params->{'destination'}"; - - # Create a sender - my $sender = SMS::Send->new( $driver, + + eval { + # Create a sender + my $sender = SMS::Send->new( $driver, _login => C4::Context->preference('SMSSendUsername'), _password => C4::Context->preference('SMSSendPassword'), ); - # Send a message - my $sent = $sender->send_sms( to => $params->{'destination'}, + # Send a message + my $sent = $sender->send_sms( to => $params->{'destination'}, text => $params->{'message'}, ); - # warn 'failure' unless $sent; - return $sent; + + # warn 'failure' unless $sent; + return $sent; + }; + #We might die because SMS::Send $driver is not defined or the sms-number has a bad format + #Catch those errors and fail the sms-sending gracefully. + if ($@) { + warn $@; + return undef; + } } =head2 driver -- 1.7.9.5