An exception has been thrown during the rendering of a template ("") Struggling to debug this one.

The full log is as follows:

Next exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("") in "book/poll-availability" at line 4.' in /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php:355
Stack trace:
#0 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(314): Twig_Template-&gt;displayWithErrorHandling(Array, Array)
#1 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(325): Twig_Template-&gt;display(Array)
#2 /var/www/craft/app/vendor/twig/twig/lib/Twig/Environment.php(293): Twig_Template-&gt;render(Array)
#3 /var/www/craft/app/services/TemplatesService.php(223): Twig_Environment-&gt;render('book/poll-avail...', Array)
#4 /var/www/craft/app/controllers/BaseController.php(74): Craft\TemplatesService-&gt;render('book/poll-avail...', Array)
#5 /var/www/craft/app/controllers/TemplatesController.php(55): Craft\BaseController-&gt;renderTemplate('book/poll-avail...', Array)
#6 [internal function]: Craft\TemplatesController-&gt;actionRender('book/poll-avail...', Array)
#7 /var/www/craft/app/framework/web/actions/CAction.php(109): ReflectionMethod-&gt;invokeArgs(Object(Craft\TemplatesController), Array)
#8 /var/www/craft/app/framework/web/actions/CInlineAction.php(47): CAction-&gt;runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
#9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction-&gt;runWithParams(Array)
#10 /var/www/craft/app/framework/web/CController.php(286): CController-&gt;runAction(Object(CInlineAction))
#11 /var/www/craft/app/framework/web/CController.php(265): CController-&gt;runActionWithFilters(Object(CInlineAction), Array)
#12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController-&gt;run('render')
#13 /var/www/craft/app/framework/web/CWebApplication.php(141): CWebApplication-&gt;runController('templates/rende...')
#14 /var/www/craft/app/etc/web/WebApp.php(279): CWebApplication-&gt;processRequest()
#15 /var/www/craft/app/framework/base/CApplication.php(184): Craft\WebApp-&gt;processRequest()
#16 /var/www/craft/app/index.php(62): CApplication-&gt;run()
#17 /var/www/public-imperialhotels/en/index.php(22): require_once('/var/www/craft/...')
#18 {main}
REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=


And the template in question looks like this:

{% set token = craft.request.getParam('search') %}

{% if (not craft.request.isAjax and not token ) %}
    {% exit 404 %}
{% endif %}

{% hook 'microsGetAvailabilityResults' %}

{% header 'Content-Type: application/json' %}

{% set data = {
    'complete': results.complete,
    'urn': results.urn,
    'pollUrl': craft.request.url ~ '?' ~ craft.request.queryStringWithoutPath
} %}

{{ data | json_encode | raw }}


So line 4 specifically is this:

    {% exit 404 %}


That should only be called if token is blank and as you can see from the REQUEST_URI, it should be set:

REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=


Any suggestions?

What's most frustrating is that this has been picked up in server log monitoring on a live box and we can't replicate it.

The template exits correctly if we hit the URL with a non-Ajax request and if no token is defined, so what gives?
You're searching in the URI for a param with a key called search:

{% set token = craft.request.getParam('search') %}


But the in the URI it's called token:

REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=


Therefore when it's not an AJAX request this passes:

{% if (not craft.request.isAjax and not token ) %}


And a 404 is thrown:

{% exit 404 %}