Refactore the code to poll again into a separate method and add an error handler for the Ajax call, handler that calls this refactored method.
In the fall-back implementation get the lastEventId value from the parsed data and add the Last-Event-ID header to the Ajax call.