Error handling

This is not the worlds greatest implementation it has a couple of things I want to fix, but I'm happy having a dumb implementation I can work on improving than no implementation, so here's a PR.