NAME
Twilio::Exceptions::TwilioServiceException - Twilio answered with an RFC 9457 problem document
SYNOPSIS
use Scalar::Util qw(blessed);
my $ok = eval { $client->numbers->v3->hosted_number_orders->create($number, 1); 1 };
if (!$ok) {
my $error = $@;
die $error unless blessed($error) && $error->isa('Twilio::Exceptions::TwilioServiceException');
warn $error->get_title, "\n";
warn " $_->{pointer}: $_->{detail}\n" for @{ $error->get_errors };
}
DESCRIPTION
Some Twilio APIs describe errors as Problem Details for HTTP APIs (RFC 9457), with type, title, status and code, and often detail, instance and a list of field errors. Any API can answer this way, so every error answer that has those four members gives this class, and anything else gives Twilio::Exceptions::RestException or Twilio::Exceptions::RestExceptionV1 as before.
This class inherits from Twilio::Exceptions::RestException, so code that catches that class catches this one too, and get_code, get_status_code and get_more_info work as they do there.
The message holds the title, the detail and the field errors, after the usual prefix:
[HTTP 400] Unable to create record: Invalid parameter - The 'PhoneNumber' parameter is required. (#/age: must be a positive integer)
METHODS
is_problem
my $yes = Twilio::Exceptions::TwilioServiceException->is_problem($decoded_body);
Returns 1 when the decoded body is a hash with type and title, and with status and code as numbers, and 0 otherwise.
new
my $error = Twilio::Exceptions::TwilioServiceException->new(
'[HTTP 400] Unable to create record', \%problem, $http_status_code
);
Builds the message from the given prefix and the problem document. Without a status code, the document's status is used.
get_type
The URL of the problem type, usually Twilio's page for the error code. get_more_info returns it too.
get_title
A short summary of the problem type.
get_detail
What went wrong in this request, or undef.
get_instance
A reference to this occurrence of the problem, or undef.
get_errors
An array reference of the field errors, each a hash with pointer (a JSON Pointer into the request) and detail. It is empty when Twilio sent none.
get_code
Inherited. Twilio's error code, such as 20001.
get_status_code
Inherited. The HTTP status of the answer.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.