Protect against HTTP errors, add more test code