Add onError for API debug