Skip to content

Commit

Permalink
fix: debug logging (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazron committed May 9, 2020
1 parent 8224312 commit e5ac05a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/commands/auth/login.js
Expand Up @@ -30,7 +30,7 @@ class LoginCommand extends ImsBaseCommand {
try {
await invalidateToken(flags.ctx, true)
} catch (err) {
// ignore failure of invalidation, continue with login
this.debugError('invalidateToken failure', err)
}
}

Expand All @@ -49,8 +49,7 @@ class LoginCommand extends ImsBaseCommand {

this.printObject(token)
} catch (err) {
const stackTrace = err.stack ? '\n' + err.stack : ''
this.debug(`Login Failure: ${err.message || err}${stackTrace}`)
this.debugError('Login failure', err)
this.error(`Cannot get token for context '${flags.ctx}': ${err.message || err}`, { exit: 1 })
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/auth/logout.js
Expand Up @@ -26,8 +26,7 @@ class LogoutCommand extends ImsBaseCommand {
try {
await invalidateToken(flags.ctx, flags.force)
} catch (err) {
const stackTrace = err.stack ? '\n' + err.stack : ''
this.debug(`Logout Failure: ${err.message || err}${stackTrace}`)
this.debugError('Logout failure', err)
this.error(`Cannot logout context '${flags.ctx}': ${err.message || err}`, { exit: 1 })
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ims-base-command.js
Expand Up @@ -31,6 +31,11 @@ class ImsBaseCommand extends Command {
return super.init()
}

debugError (message, err) {
const stackTrace = err.stack ? '\n' + err.stack : ''
this.debug(`${message}: ${err.message || err}${stackTrace}`)
}

printObject (obj) {
const { flags } = this.parse(this.constructor)

Expand Down

0 comments on commit e5ac05a

Please sign in to comment.