Created
April 13, 2017 21:42
-
-
Save rinogo/5958c4a60905a963673317656e055c6c to your computer and use it in GitHub Desktop.
An example of how to use the `.catch()` mechanism in NightmareJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Nightmare = require("nightmare"); | |
var nightmare = new Nightmare(); | |
nightmare | |
.goto("https://non-existent-website-nifgeoawniogea.com") | |
.catch(handleError); | |
//Note: You can manually raise an exception from within a `.then()` command with a normal `throw new Error()`: | |
//throw new Error("Description of the error."); | |
function handleError(error) { | |
nightmare.end().then(); | |
var message; | |
if(typeof error.details != "undefined" && error.details != "") { | |
message = error.details; | |
} else if(typeof error == "string") { | |
message = error; | |
if(error == "Cannot read property 'focus' of null") { | |
message += " (Likely because a non-existent selector was used)"; | |
} | |
} else { | |
message = error.message; | |
} | |
console.error({"status": "error", "message": message}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also