getBills method
Retrieve a List<BillBaseDto> with the bills of 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. -
changesSince
can be used to retrieve bill changes after a specific datetime -
take
can be used to specify the amount of bills to take for pagination -
skip
can be used to specify the amount of bills to skip for pagination
Returns a AnybillResult.success that contains the status code and the bill list.
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<List<BillBaseDto>>> getBills({
int requestCount = 2,
String? changesSince,
int take = 100,
int skip = 0,
}) async {
AnybillLogger.info("Tried to get bills");
try {
final token = await _tokenProvider.getToken();
if (token == null) {
return AnybillResult.failure(
type: AnybillErrorType.noUserError,
);
}
// Makes a request to fetch the user bills
final userBills = await _billService.getBillChangesList(
token: token,
changesSince: changesSince,
take: take,
skip: skip,
);
if (userBills.data.isEmpty) {
return AnybillResult.success(
HttpStatus.noContent,
data: userBills.data,
);
}
await _billStore.putBillsData(userBills.data);
return AnybillResult.success(HttpStatus.ok, data: userBills.data);
}
// ----------------------------------------------------------------
catch (error, stacktrace) {
return ErrorHandler.handleError(
error,
stacktrace,
requestCount: requestCount,
request: () => getBills(
requestCount: requestCount - 1,
changesSince: changesSince,
skip: skip,
take: take,
),
event: "getBills",
library: runtimeType.toString(),
);
}
}