catch ValueError in API