Пример #1
0
    def instance_url(self):
        id = self.get("id")

        if not isinstance(id, six.string_types):
            raise error.InvalidRequestError(
                "Could not determine which URL to request: %s instance "
                "has invalid ID: %r, %s. ID should be of type `str` (or"
                " `unicode`)" % (type(self).__name__, id, type(id)),
                "id",
            )

        id = util.utf8(id)
        extn = quote_plus(id)
        return "/v2/phone_numbers/%s/voice" % extn
Пример #2
0
    def specific_api_error(self, rbody, rcode, resp, rheaders, error_list):
        for err in error_list:
            util.log_info(
                "Telnyx API error received",
                error_code=err.get("code"),
                error_detail=err.get("detail"),
                error_source=err.get("source"),
                error_title=err.get("title"),
            )

        if rcode == 400:
            return error.InvalidRequestError(error_list, rbody, rcode, resp,
                                             rheaders)
        elif rcode == 401:
            return error.AuthenticationError(error_list, rbody, rcode, resp,
                                             rheaders)
        elif rcode == 403:
            return error.PermissionError(error_list, rbody, rcode, resp,
                                         rheaders)
        elif rcode == 404:
            return error.ResourceNotFoundError(error_list, rbody, rcode, resp,
                                               rheaders)
        elif rcode == 405:
            return error.MethodNotSupportedError(error_list, rbody, rcode,
                                                 resp, rheaders)
        elif rcode == 408:
            return error.TimeoutError(error_list, rbody, rcode, resp, rheaders)
        elif rcode == 415:
            return error.UnsupportedMediaTypeError(error_list, rbody, rcode,
                                                   resp, rheaders)
        elif rcode == 422:
            return error.InvalidParametersError(error_list, rbody, rcode, resp,
                                                rheaders)
        elif rcode == 429:
            return error.RateLimitError(error_list, rbody, rcode, resp,
                                        rheaders)
        elif rcode == 500:
            return error.APIError(error_list, rbody, rcode, resp, rheaders)
        elif rcode == 503:
            return error.ServiceUnavailableError(error_list, rbody, rcode,
                                                 resp, rheaders)
        else:
            return error.APIError(error_list, rbody, rcode, resp, rheaders)
 def retrieve(cls, id, api_key=None, **params):
     raise error.InvalidRequestError("%s does not support retrieve()" %
                                     cls.class_url())