better error handling in api client