handling failures in APIs