Skip to content

Commit

Permalink
fix(isLogObj): handle non-standard error objects
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 19, 2018
1 parent 40e6311 commit 8748c81
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ export function isPlainObject (obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
}

// TODO: remove for consola@3
export function isLogObj (arg) {
// Should be plain object
// Also contains either message or args field
return isPlainObject(arg) && (Boolean(arg.message || arg.args))
if (!isPlainObject(arg)) {
return false
}

// Should contains either 'message' or 'args' field
if (!arg.message && !arg.args) {
return false
}

// Handle non-standard error objects
if (arg.stack) {
return false
}

return true
}

0 comments on commit 8748c81

Please sign in to comment.