res could be nil, pls check against nil before accessing it:

```ruby
if res and res.code == 200
```