Preview Expired Fail More Gracefully?

I know this has been discussed before. Preview tokens expire but my issue is that the way it fails is spectacular, maybe it is an issue of my implementation or the PHP Api:

When working locally I’m able to see the error. On the live server I only get a 500 error. Because the page never loads there is no way to click the “x” on the prismic toolbar as suggested in other forum posts.

Going to the editor and clicking the preview button again also does not resolve the issue. The only way is to clear cookies and this also logs you out of prismic which is annoying.

Maybe I’m doing something wrong on my implementation? Pretty much followed the docs. This is also not addressed on the “Troubleshooting Previews” articles.

It would be nice to catch this exception to automatically delete the cookie or show a 404. Also if clicking the preview button on the editor reissued the token.

Hola Nehemek, thanks for reaching out!

This is a very strange warning, I’m not sure what the issue might be.
If you could give us some more details it’ll be very helpful:

  • The 500 error appearing in the live server
  • Which SDK are you using?
  • Are you loading the preview script in the head of every page?
  • Are you on Mac or Windows?
  • If using chrome, can you check in chrome://flags Search for samesite and then disable this option => samesite by default cookies and see if it’s enabled or not?

Hello,

Here are the last two errores on the error_log file which are identical to what happens in local:

[27-Aug-2020 13:33:54 America/New_York] PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://nehemek-site.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=20&access_token=MC5YckF1aVJFQUFDSUFub1dH.YU8GQe-_vR5Y77-977-977-977-9FO-_ve-_vSbvv70RSQl977-9Mhli77-9Czvvv73vv73vv71X77-9&ref=%7B%22_tracker%22%3A%22QzmPyhFD%22%2C%22nehemek-site.prismic.io%22%3A%7B%22preview%22%3A%22https%3A%2F%2Fnehemek-site.prismic.io%2Fpreviews%2FX0VFxBAAAB2Hxuo_%3AX0fE3BAAAGKj0gbC%3FwebsitePreviewId%3DXr4o4xAAACgzx5-a%22%7D%7D&q=%5B%5B%3Ad%20%3D%20at%28document.type%2C%20%22settings%22%29%5D%5D resulted in a 404 Not Found response:
{“error”:“This preview token has expired”,“oauth_initiate”:"https://nehemek-site.cdn.prismic.io/auth",“oauth_token”:"htt (truncated…)
in /home/neheghzf/public_html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/neheghzf/public_html/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\P in /home/neheghzf/public_html/vendor/prismic/php-sdk/src/Prismic/Exception/RequestFailureException.php on line 52

[27-Aug-2020 13:49:25 America/New_York] PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://nehemek-site.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=20&access_token=MC5YckF1aVJFQUFDSUFub1dH.YU8GQe-_vR5Y77-977-977-977-9FO-_ve-_vSbvv70RSQl977-9Mhli77-9Czvvv73vv73vv71X77-9&ref=%7B%22_tracker%22%3A%22QzmPyhFD%22%2C%22nehemek-site.prismic.io%22%3A%7B%22preview%22%3A%22https%3A%2F%2Fnehemek-site.prismic.io%2Fpreviews%2FX0VFxBAAAB2Hxuo_%3AX0fE3BAAAGKj0gbC%3FwebsitePreviewId%3DXr4o4xAAACgzx5-a%22%7D%7D&q=%5B%5B%3Ad%20%3D%20at%28document.type%2C%20%22settings%22%29%5D%5D resulted in a 404 Not Found response:
{“error”:“This preview token has expired”,“oauth_initiate”:"https://nehemek-site.cdn.prismic.io/auth",“oauth_token”:"htt (truncated…)
in /home/neheghzf/public_html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/neheghzf/public_html/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\P in /home/neheghzf/public_html/vendor/prismic/php-sdk/src/Prismic/Exception/RequestFailureException.php on line 52

The SDK being used is Prismic PHP 5.1.1

The toolbar is indeed loaded in every page but this error is server sided so the page never renders, it just fails.

I’m using Windows.

This happens on Opera and Brave browser. To test on other browsers I would need to do a preview and wait until it expires tomorrowish, but I’m pretty certain it has happened to me in Chrome before.

Hey Nehemek,

The preview token doesn’t expire with time but when a change has been made to the document. As discussed in the preview troubleshooting article:

The preview token expires once the saved information has been archived or published. The preview token generated is only valid for the information being previewed at that time.

I like your idea to catch the exception and delete the cookie, though I’m not sure how you would implement this. Normally it shouldn’t cause the failure you see above, but it should give you a error on the screen saying the token has expired.

Do you know what version of the toolbar you’re using? Does the preview script have the query string ?new=true?

This issue has been closed due to inactivity.