Handling request and response errors

Closes #556