@viewdo/dxp-story-cli
Version:
README.md
68 lines (52 loc) • 1.38 kB
JavaScript
require('colors')
// properties -------------------------------
const debug_flag = process.env.VERBOSE || process.env.DEBUG || false
const prefix = 'DXP Story CLI:'.blue
// console API -------------------------------
const log = (message) => {
console.log(`${prefix} ${message}`)
}
const debug = (message) => {
if(debug_flag)
console.log(`${prefix} ${message}`.gray)
}
const dir = (object) => {
console.dir(object)
}
const info = (message) => {
if(debug_flag)
console.info(`${prefix} ${message.gray}`)
}
const error = (message = 'An error has occurred') => {
console.log(`${prefix} ${message}`.red)
}
const axiosError = (err) => {
if (err.response) {
/*
* The request was made and the server responded with a
* status code that falls out of the range of 2xx
*/
error(err.response.data)
error(err.response.status)
error(err.response.headers)
} else if (error.request) {
/*
* The request was made but no response was received, `error.request`
* is an instance of XMLHttpRequest in the browser and an instance
* of http.ClientRequest in Node.js
*/
error(err.request)
} else {
// Something happened in setting up the request and triggered an Error
console.log('Error', err.message || err)
}
}
module.exports = {
log,
debug,
dir,
info,
error,
axiosError,
prefix
}