Add framework for handling XHR errors

Closes #128