Since the find method returns a List it would be empty, you can check if the list is empty and then throw a Serialsable exception.
However, in your query, it looks like you are only interested in a specific row. There is a special function for this use case that you can use instead, findById
that takes the session object and an id.
Future<Business> getBusiness(Session session, int id) async {
final business = await Business.findById(
session,
id
);
if (business == null) {
throw NotFound();
}
return business;
}
In your protocol folder you would have something like this:
## not_found.yaml
exception: NotFound
fields:
message: String
On the client side:
try {
final result = await client.business.getBusiness(id);
} on (NotFound) catch (error) {
// Handle not found.
} catch (error) {
// Unexpected error.
}