getUserInformation method

Future<AnybillResult<UserInformationDto>> getUserInformation(
  1. {int requestCount = 2}
)

Retrieve an UserInformationDto from the current authenticated user.

  • requestCount can be used to determine the number of repeated requests before a failure is returned if the call is not successful.

Returns a AnybillResult.success that contains the status code and the user information in its data parameter.

Throws a AnybillResult.failure with the specified information gained from the API. This could be a DioException when a generic errors occurred or a different Exception for critical errors that couldn't be caught.

Implementation

Future<AnybillResult<UserInformationDto>> getUserInformation({
  int requestCount = 2,
}) async {
  AnybillLogger.info("Tried to get user information");
  try {
    final token = await _tokenProvider.getToken();
    if (token == null) {
      return AnybillResult.failure(
        type: AnybillErrorType.noUserError,
      );
    }

    final userInfo = await _userService.getUserSelf(token: token);

    await _userStore.putUserInformation(userInfo);

    return AnybillResult.success(
      HttpStatus.ok,
      data: userInfo,
    );
  }
  // ----------------------------------------------------------------
  catch (error, stacktrace) {
    return ErrorHandler.handleError(
      error,
      stacktrace,
      requestCount: requestCount,
      request: () => getUserInformation(requestCount: requestCount - 1),
      event: "getUserInformation",
      library: runtimeType.toString(),
    );
  }
}