twilio / twilio-go

A Go package for communicating with the Twilio API.
MIT License
278 stars 40 forks source link

ListServiceConversationMessage(): "could not retrieve payload from response" #114

Closed zs-codex closed 2 years ago

zs-codex commented 2 years ago

Issue Summary

The ConversationsV1 REST API for ListServiceConversationMessage() returns the following error if no messages exist in the conversation:

| could not retrieve payload from response

However, we would expect the returned result to be either

  1. An empty slice instead with no error
  2. A Twilio-defined error API code from the list.

Steps to Reproduce

  1. Query any conversation that contains no messages

Code Snippet

messages, err := client.ConversationsV1.ListServiceConversationMessage(serviceSid, conversationUniqueName, &conversations.ListServiceConversationMessageParams{})

Exception/Log

# paste exception/log here

Technical details:

shwetha-manvinkurke commented 2 years ago

Makes sense. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

Internal tracking

mwajeeh commented 2 years ago

It is a generic issue in paging library which throws error could not retrieve payload from response if there is no result. I am getting it on ListPhoneNumber() api.

shwetha-manvinkurke commented 2 years ago

@mwajeeh Yup we are aware of it. It's in the backlog being prioritized.

sarahcstringer commented 2 years ago

+1, also seeing this on PlayerStreamer and MediaProcessor list resources.

saurori commented 2 years ago

I believe I tracked down this problem. It has to do with response types having omitempty.

An example of this can be seen on the ListCallResponse. If omitempty is removed, the Calls struct will have an empty slice value and will be present when the response is marshaled in toMap. The page_util.go code will detect the empty slice and append it to the data slice, and not cause an error.

If you look at an empty json response to the Calls endpoint, the "calls": [] empty array indicates the field has empty data and not null data. Therefore I think that omitempty is incorrect and the response field should not be nullable (in the OAI spec?).

{
    "first_page_uri": "/2010-04-01/Accounts/ACxx/Calls.json?EndTime%3C=2021-11-27T10%3A22%3A51+00%3A00&StartTime%3E=2021-11-27T16%3A22%3A51+00%3A00&PageSize=20&Page=0",
    "end": 0,
    "calls": [],
    "previous_page_uri": null,
    "uri": "/2010-04-01/Accounts/ACxx/Calls.json?EndTime%3C=2021-11-27T10%3A22%3A51+00%3A00&StartTime%3E=2021-11-27T16%3A22%3A51+00%3A00&PageSize=20&Page=0",
    "page_size": 20,
    "start": 0,
    "next_page_uri": null,
    "page": 0
}
childish-sambino commented 2 years ago

Fixed by https://github.com/twilio/twilio-go/pull/148