getCachedUserInformation method

Future<AnybillResult<UserInformationDto>> getCachedUserInformation()

Retrieve the cached user information data from the database.

Returns an instance of Success with the UserInformationDto object as data if it exists in the cache otherwise returns instance of Failure with type AnybillErrorType.genericError and code HttpStatus.notFound is returned.

In case of an internal error, instance of Failure with AnybillErrorType.unknown is returned

Implementation

Future<AnybillResult<UserInformationDto>> getCachedUserInformation() async {
  try {
    final data = await _userStore.getUserInformation();
    if (data != null) {
      return AnybillResult.success(
        HttpStatus.ok,
        data: data,
      );
    } else {
      return AnybillResult.failure(
        type: AnybillErrorType.genericError,
        code: HttpStatus.notFound,
      );
    }
  } catch (error, stacktrace) {
    AnybillLogger.error(
      error: error,
      stacktrace: stacktrace,
      library: runtimeType.toString(),
      event: "getCachedUserInformation",
    );
    return AnybillResult.failure(
      type: AnybillErrorType.unknown,
      message: error.toString(),
    );
  }
}