backend: cleanup error handling logic

I was reviewing this code and had a hard time reasoning about it. I
think this clears things up. Totally untested though.