Skip to content

Commit

Permalink
Merge pull request #76 from Seneca-CDOT/bugs/401-error
Browse files Browse the repository at this point in the history
fix: jsdom crashing on 401 errors
  • Loading branch information
poftadeh committed Nov 20, 2019
2 parents 017bf4f + bfeadce commit 9189039
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Browser/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,35 @@ class Browser {
this.activeElement = this.dom.window.document.activeElement;
}

/**
* handles errors thrown by the navigation function
*/
private handleNavigationError(error, config) {
// the jsdom instance will otherwise crash on a 401
if (error.statusCode === 401) {
this.dom = new JSDOM(' ', {
resources: config.resourceLoader,
runScripts: config.runScripts,
beforeParse: config.beforeParse,
pretendToBeVisual: true,
cookieJar: config.jar,
});
} else {
throw error;
}
}

/**
* accepts a url and pathType @type {String} from which to instantiate the
* jsdom object
*/
async navigate(path: URL, pathType) {
if (path) {
await this.configureBrowser(this.browserConfig, path, pathType);
try {
await this.configureBrowser(this.browserConfig, path, pathType);
} catch (error) {
this.handleNavigationError(error, this.browserConfig);
}
}
return true;
}
Expand Down

0 comments on commit 9189039

Please sign in to comment.