Response Handling
Every data-fetching operation in the SDK returns a Result, which models either a success (Ok) or a failure (Err). This design ensures you handle both outcomes explicitly, making your code more predictable and safer by default.
You can work with the result in several ways:
Using when Expression
This is the most explicit and idiomatic way to handle both cases:
Using Convenience Functions
The Result class includes helper methods for more concise handling:
unwrap(): Returns the value if successful, or throws if it’s an error.unwrapErr(): Returns the error if failed, or throws if it’s successful.expect("message"): Likeunwrap(), but includes a custom error message.expectErr { "message" }: LikeunwrapErr(), with a custom error message.
Use these when you’re confident about the outcome, or in testing/debug scenarios where failure should immediately surface.