Add error handling

Handle errors in the SDK.
This is a breaking change, so needs a minor bump.