how to fix twilio-php uncaught exception on lookup of bad number? -
i'm weak on how throwing exceptions works...
i'm getting following when entering bad number in lookup:
fatal error: uncaught exception 'services_twilio_restexception' message 'the requested resource /phonenumbers/310-69-5340 not found' in /home/jimbursch/includes/twilio-php/services/twilio.php:297 stack trace: #0 /home/jimbursch/includes/twilio-php/services/twilio.php(265): base_services_twilio->_processresponse(array) #1 /home/jimbursch/includes/twilio-php/services/twilio.php(236): base_services_twilio->_makeidempotentrequest(array, '/v1/phonenumber...', 1) #2 /home/jimbursch/includes/twilio-php/services/twilio/instanceresource.php(79): base_services_twilio->retrievedata('/v1/phonenumber...') #3 /home/jimbursch/includes/site_functions.php(655): services_twilio_instanceresource->__get('phone_number') #4 /home/jimbursch/includes/admin/misc.php(43): lookupphone('310-69-5340')
here believe happening:
private function _processresponse($response) { list($status, $headers, $body) = $response; if ($status === 204) { return true; } $decoded = json_decode($body); if ($decoded === null) { throw new services_twilio_restexception( $status, 'could not decode response body json. ' . 'this indicates 500 server error' ); } if (200 <= $status && $status < 300) { $this->last_response = $decoded; return $decoded; } throw new services_twilio_restexception( $status, isset($decoded->message) ? $decoded->message : '', isset($decoded->code) ? $decoded->code : null, isset($decoded->more_info) ? $decoded->more_info : null ); }
you have catch
exception.
rightfully, twilio sdk throws exception when errors.
you have following:
<?php ... try { //your twilio code you'd execute } catch( services_twilio_restexception $e ) { echo $e->getmessage(); // or maybe log // handle fact "the requested resource /phonenumbers/310-69-5340 not found" }
by catching error message, avoid fatal error
, script can continue working, allowing register operation failed (or reported else useful back).
Comments
Post a Comment