Skip to content

Instantly share code, notes, and snippets.

@itzexor
Created April 29, 2017 05:04
Show Gist options
  • Save itzexor/581a51927694ba1a185d2f7eb3928031 to your computer and use it in GitHub Desktop.
Save itzexor/581a51927694ba1a185d2f7eb3928031 to your computer and use it in GitHub Desktop.
/**
* 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