Better handling of HTTP errors. Fixes #4