getFirstListItem method
Returns the first found list item by the specified filter.
Internally it calls getList()
and returns its first item.
For consistency with getOne
, this method will throw a 404
ClientException
if no item was found.
Implementation
Future<M> getFirstListItem(
String filter, {
String? expand,
String? fields,
Map<String, dynamic> query = const {},
Map<String, String> headers = const {},
}) {
return getList(
perPage: 1,
skipTotal: true,
filter: filter,
expand: expand,
fields: fields,
query: query,
headers: headers,
).then((result) {
if (result.items.isEmpty) {
throw ClientException(
statusCode: 404,
response: <String, dynamic>{
"code": 404,
"message": "The requested resource wasn't found.",
"data": <String, dynamic>{},
},
);
}
return result.items.first;
});
}