callServerEndpoint<T> method
Calls a server endpoint method by its name, passing arguments in a map. Typically, this method is called by generated code.
Implementation
@override
Future<T> callServerEndpoint<T>(
String endpoint,
String method,
Map<String, dynamic> args, {
bool authenticated = true,
}) async {
try {
return await _callServerEndpoint(
endpoint,
method,
args,
authenticated: authenticated,
);
} on ServerpodClientUnauthorized catch (_) {
final keyProvider = authKeyProvider;
// A first failure here with 401 can be due to an access token expiration.
// We will retry only once in such case, and only if the `authKeyProvider`
// exposes a `refreshAuthKey` method (like JWT).
if (keyProvider is RefresherClientAuthKeyProvider) {
final refreshResult = await keyProvider.refreshAuthKey();
if (refreshResult == RefreshAuthKeyResult.success) {
return _callServerEndpoint(
endpoint,
method,
args,
authenticated: authenticated,
);
}
}
rethrow;
}
}