@@ -2,6 +2,7 @@ import {Constants} from "../constants";
2
2
import { PromiseUtils } from "../promiseUtils" ;
3
3
import { Settings } from "../settings" ;
4
4
import { StringUtils } from "../stringUtils" ;
5
+ import { UserInfo } from "../userInfo" ;
5
6
6
7
import { Clipper } from "../clipperUI/frontEndGlobals" ;
7
8
@@ -179,19 +180,45 @@ export class SaveToOneNote {
179
180
180
181
Promise . all ( [ getRevisionsPromise , timeoutPromise ] ) . then ( ( values ) => {
181
182
let revisions = values [ 0 ] as OneNoteApi . Revision [ ] ;
182
- this . getApi ( ) . updatePage ( pageId , revisions ) . then ( ( ) => {
183
+
184
+ let thenCb = ( ) => {
183
185
timeBetweenPatchRequests = SaveToOneNote . timeBetweenPatchRequests ;
184
186
resolve ( ) ;
185
- } ) . catch ( ( error ) => {
186
- reject ( error ) ;
187
- } ) ;
187
+ } ;
188
+
189
+ let catchCb = ( error : OneNoteApi . RequestError ) => {
190
+ if ( error . statusCode === 401 ) {
191
+ // The clip has taken a really long time and the user token has expired
192
+ Clipper . getExtensionCommunicator ( ) . callRemoteFunction ( Constants . FunctionKeys . ensureFreshUserBeforeClip , {
193
+ callback : ( updatedUser : UserInfo ) => {
194
+ if ( updatedUser . user . accessToken ) {
195
+ // Try again with the new token
196
+ this . accessToken = updatedUser . user . accessToken ;
197
+ this . updatePage ( pageId , revisions , thenCb , catchCb ) ;
198
+ } else {
199
+ reject ( error ) ;
200
+ }
201
+ }
202
+ } ) ;
203
+ } else {
204
+ reject ( error ) ;
205
+ }
206
+ } ;
207
+
208
+ this . updatePage ( pageId , revisions , thenCb , catchCb ) ;
188
209
} ) ;
189
210
} ) ;
190
211
} ) ;
191
212
} , this . getApi ( ) . getPageContent ( pageId ) ) // Check if page exists with retries
192
213
] ) ;
193
214
}
194
215
216
+ private updatePage ( pageId : string , revisions : OneNoteApi . Revision [ ] , thenCb : ( ) => void , catchCb : ( error : OneNoteApi . RequestError ) => void ) {
217
+ this . getApi ( ) . updatePage ( pageId , revisions )
218
+ . then ( thenCb )
219
+ . catch ( catchCb ) ;
220
+ }
221
+
195
222
// We try not and put logging logic in this class, but since we lazy-load images, this has to be an exception
196
223
private getPatchWithLogging ( saveable : OneNoteSaveable , index : number ) : Promise < OneNoteApi . Revision [ ] > {
197
224
let event = new Log . Event . PromiseEvent ( Log . Event . Label . ProcessPdfIntoDataUrls ) ;
0 commit comments