The current problem here is that we assign err if !response but still continue to assign code fron response.statusCode on line 48.

Just making a change. @bobmayo56 prefer to handle it this away although your solution seems good.