Error when no data available for getKeywordsFromCampaignId

I created the following report:

public function getExampleCampaign($idSite, $period, $date, $segment = false)
        $segment .= "referrerName==example";
        return \Piwik\Plugins\Referrers\API::getInstance()->getKeywordsFromCampaignId($idSite, $period, $date, 1, $segment);


This works fine as long as there is any campaign data, but when i select a date/period where no campaigns have been tracked i get the following error:

Oops… there was a problem during the request. Maybe the server had a temporary issue, or maybe you requested a report with too much data. Please try again. If this error occurs repeatedly please contact your Matomo administrator for assistance.

Why does this happen? Do i have to check for something? I would want it to say:
There is no data for this report.