Created
April 29, 2017 05:04
-
-
Save itzexor/581a51927694ba1a185d2f7eb3928031 to your computer and use it in GitHub Desktop.
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
/** | |
* isError: | |
* @obj (Object): the object to be tested | |
* | |
* Tests whether @obj is an error object. If the object | |
* is a GLib.Error then we add a stack trace to it. | |
* | |
* Returns (boolean): whether @obj is an error object | |
*/ | |
function isError(obj) { | |
let isErr = false; | |
if (typeof(obj) == 'object' && 'message' in obj && 'stack' in obj) { | |
isErr = true; | |
} else if (obj instanceof GLib.Error) { | |
let stack = Error().stack; | |
stack = stack.substr(stack.indexOf('\n') + 1); | |
obj.stack = stack; | |
isErr = true; | |
} | |
return isErr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment