handle and log API errors