Future<List<Business>> getBusiness(Session session, {int? id}) async {
return await Business.find(
session,
where: (t) => id != null ? t.id.equals(id) : Constant(true),
);
}
How to return the error model if any error happens, like if the id doesn't exist or something
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,
findByIdthat takes the session object and an id.In your protocol folder you would have something like this:
On the client side: