Skip to main content
Question

Error handling in'Javascript Preview SDK'

  • May 21, 2025
  • 2 replies
  • 34 views

Forum|alt.badge.img

Hi,

I'm using Javascript Preview SDK

https://cdn01.boxcdn.net/platform/preview/0.96.0/en-US/preview.js
https://cdn01.boxcdn.net/platform/preview/0.96.0/en-US/preview.css

 

I've used below method to preview multiple files, 

Box.Preview.show(fileId, accessToken, {
    container: '.preview-container',
    sharedLink: 'https://app.box.com/v/foo',
    sharedLinkPassword: 'bar',
    collection: [fileId, '123', '234', ...],
    header: 'light',
    logoUrl: 'http://i.imgur.com/xh8j3E2.png',
    showDownload: true,
});

When access token expired i'm getting error like "We're sorry, the preview didn't load. Please refresh the page."

 

 How can I catch, access token expired moment. So that I can call new access token api.

 

Thanks in advance.

2 replies

Forum|alt.badge.img

 I agree this would be a valuable feature to have. I asked the team who created this SDK. Unfortunately, there is currently nothing implemented in the SDK to help you catch the token expiration event.


Forum|alt.badge.img

Thanks for your response.

 

Currently I've taken advantage of load event to handle this situation. Like, 

 

Box.Preview.on("load",function(resp){
    if( typeof resp.error !== 'undefined' )
Box.Preview.updateToken(); });

 

response:  

{
"error":"We're sorry, the preview didn't load. Please refresh the page.", "metrics":{
"locale":"en-US", "event":"preview", "browser":{ "name":"Chrome","swf":true,"svg":true,"mse":true,"webgl":true,"mp3":true,"dash":true,"box3d":true, "h264":{"baseline":true,"main":true,"high":true} }, "converted":true,"cache":{"hit":false,"stale":false}, "time":{"conversion":0,"rendering":398,"total":398}, "count":{"success":0,"error":1,"navigation":0}}, "file":{"id":""}
}

 Here, When I call update token method,

Box.Preview.updateToken();

 Its doing two tasks

    1. Updates the token - Worked.

    2. Retries to load the current file which was failed. - Not Working, Still failing to load,

Issue might be, cached requests of current file.  Because, viewing any other file in the collection loads fine. after that if I try to view the failed file that also works.

 

Please help me to resolve this issue.