intercom / intercom-go

Go Bindings For Intercom
https://developers.intercom.io/reference
Other
70 stars 78 forks source link

`index out of range` panic due to >= 400 API response #52

Closed neilgarb closed 7 years ago

neilgarb commented 7 years ago

Version info

No panic.

Actual behavior

One of our services panicked overnight due to an index out of range error. The offending code is in IntercomHTTPClient.parseResponseError, which expects errorList.Errors to have at least one entry. I'm not sure what the JSON payload was because it wasn't logged, but we seem to have gotten a response from the API which had status >= 400, contained valid JSON but had an empty errors array.

Steps to reproduce

None - seems to have been a once-off server response.

Logs

 panic: runtime error: index out of range
 goroutine 370 [running]:
 panic(0xf75560, 0xc4200120f0)
 #011/usr/local/Cellar/go/1.7/libexec/src/runtime/panic.go:500 +0x1a1
 gopkg.in/intercom/intercom-go.v2/interfaces.IntercomHTTPClient.parseResponseError(0xc422a8fe90, 0xc422d687f0, 00, 0xc422d68810, 0xc42407a000, 0x30, ...)
 #011/.../src/gopkg.in/intercom/intercom-go.v2/interfaces/http_client.go:160 +0x183
 gopkg.in/intercom/intercom-go.v2/interfaces.IntercomHTTPClient.postOrPatch(0xc422a8fe90, 0xc422d687f0, 0x7ffc61bbca49, , 0x10e683a, 0x4, ...)
 #011/.../src/gopkg.in/intercom/intercom-go.v2/interfaces/http_client.go:113 +0x4e6
 gopkg.in/intercom/intercom-go.v2/interfaces.IntercomHTTPClient.Post(0xc422a8fe90, 0xc422d687f0, 0x7ffc61bbca49, 0x8, 0e8c9b, 0x6, ...)
 #011/.../src/gopkg.in/intercom/intercom-go.v2/interfaces/http_client.go:77 +0x9b
 gopkg.in/intercom/intercom-go.v2/interfaces.(*IntercomHTTPClient).Post(0xc422239b40, 0x10e8c9b, 0x6, 0x10baf40, d)
 #011<autogenerated>:12 +0xb2
 gopkg.in/intercom/intercom-go%2ev2.UserAPI.save(0x181fdc0, 0xc422239b40, 0xc422c4cfc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
 #011/.../src/gopkg.in/intercom/intercom-go.v2/user_api.go:66 +0x106
 gopkg.in/intercom/intercom-go%2ev2.(*UserAPI).save(0xc42363ce50, 0xc422c4cfc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
 #011<autogenerated>:81 +0xb0
 gopkg.in/intercom/intercom-go%2ev2.(*UserService).Save(0xc422d68710, 0xc422c4cfc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
 #011/.../src/gopkg.in/intercom/intercom-go.v2/user.go:127 +0x82