when<T> method

T when<T>({
  1. required T success(
    1. UserInfo userInfo,
    2. TokenResponse tokens
    ),
  2. required T failure(
    1. FrappeAuthException error
    ),
})

Executes appropriate callback based on result

Implementation

T when<T>({
  required T Function(UserInfo userInfo, TokenResponse tokens) success,
  required T Function(FrappeAuthException error) failure,
}) {
  if (this.success && userInfo != null && tokens != null) {
    return success(userInfo!, tokens!);
  } else if (error != null) {
    return failure(error!);
  } else {
    throw StateError('AuthResult is in an invalid state');
  }
}