Skip to content

The result type

Those of you familiar with Rust will feel right at home with the Result type this library implements. All requests that go out over the network via the Client come back to you in the form of a Result. The result can be one of two things: an Ok or an Err.

Info

Service methods never raise on an API error. A failed request comes back as an Err wrapping an HttpErrorResponse, so you branch on the result instead of wrapping calls in try/except.

The API

Always check is_ok (or is_err) before unwrapping, so you unwrap the variant you actually have.

Correct usage

client = wom.Client(user_agent="@jonxslays")

await client.start()

result = await client.players.update_player("jonxslays")

if result.is_ok:
    print(result.unwrap())
else:
    print(result.unwrap_err())

await client.close()

Incorrect usage

client = wom.Client(user_agent="@jonxslays")

await client.start()

result = await client.players.update_player("eeeeeeeeeeeee")

print(result.unwrap()) # <-- Exception raised
# Raises UnwrapError because username should have been 12 characters or less

# .. Remember to close the client!