Add error handling

Handle errors in the SDK.