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
is_ok/is_err- booleans identifying the variant.unwrap()- returns the value on anOk; raisesUnwrapErroron anErr.unwrap_err()- returns the error on anErr; raisesUnwrapErroron anOk.to_dict()-{"value": ..., "error": None}for anOk, and the mirror for anErr.
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()