Check for err before checking the response code

In the case where we have an error and no response object, we crash on:

TypeError: Cannot read property 'statusCode' of undefined

We should be able to assume that we have either an error or a response
object, so just switching the order in the conditional should prevent
checking the null response object.