Fixed error handling and apiCode being set.