deleteBills method
Delete a given list of bills of the currently authenticated user.
-
requestCount
can be used to determine the number of repeated requests before a failure is returned if the call is not successful. -
billIds
contains the list of the bills that should be deleted.
Returns a AnybillResult.success that contains the status code.
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<void>> deleteBills({
int requestCount = 2,
required List<String> billIds,
}) async {
AnybillLogger.info("Tried to delete ${billIds.length} bills");
try {
final token = await _tokenProvider.getToken();
if (token == null) {
return AnybillResult.failure(
type: AnybillErrorType.noUserError,
);
}
// Makes a request to delete the given user bills
await _billService.deleteBill(
token: token,
body: billIds,
);
return AnybillResult.success(
HttpStatus.noContent,
);
}
// ----------------------------------------------------------------
catch (error, stacktrace) {
return ErrorHandler.handleError(
error,
stacktrace,
requestCount: requestCount,
request: () => deleteBills(
requestCount: requestCount - 1,
billIds: billIds,
),
event: "deleteBills",
library: runtimeType.toString(),
);
}
}