zendesk / zendesk_api_client_rb

Official Ruby Zendesk API Client
http://developer.zendesk.com/
Apache License 2.0
387 stars 183 forks source link

Error on build request "NoMethodError: undefined method `<<' for nil:NilClass" #363

Closed shir closed 2 years ago

shir commented 6 years ago

When I build a new request:

   api.request.build(
      subject:        subject,
      comment:        { body: description },
      ticket_form_id: request_form_id,
    )

I got error:

NoMethodError: undefined method `<<' for nil:NilClass

It happens here zendesk_api-1.14.2/lib/zendesk_api/collection.rb" line 166 in <<.

I've investigated a bit and found that this happens because @resources is nil. I've tried to figure out why it's nil and found only one scenario. In method << at first step fetch is called to fill @resources but fetch calls fetch! and if Faraday::Error::ClientError appear then [] is returned, but @resources is not set (I guess fetch in case of error should assign [] to @resources before return it). And I've tried to reproduce this behaviour by turning off network on my machine and got same result - exception "NoMethodError: undefined method `<<' for nil:NilClass".

I think in case Faraday::Error::ClientError it should not be silences (at least when build is called) and should raise exception with information why this happen. In my case I suspect that issue is not with internet connection because user make other request via API successfully, but I can't get any information about issue.

andheiberg-babylonhealth commented 2 years ago

I came here with similar problems and the solution seems reasonable to me.

ecoologic commented 2 years ago

@andheiberg-babylonhealth : while @shir 's suggestion makes a lot of sense, I wasn't able to reproduce this specific error in the issue description.

Would you have a more updated code I can use for my testing?

Thank you.

ecoologic commented 2 years ago

2018 error that can't be reproduced. Closing for now, please feel free to re-open and provide an example to reproduce, if you have the same error.