Tidy up backend error handling.

This handles all errors here, which will aviod duplicating generic errors between the error json log and the `STDERR` output.