You also need to check response.statusCode. It may end up with an HTTP 500, but the err will be null.