2018-03-09 05:33:43 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
module.exports = {
|
2018-03-10 05:58:04 +00:00
|
|
|
generateSuccess (msg) {
|
|
|
|
return {
|
|
|
|
succeeded: true,
|
2018-03-25 02:35:47 +00:00
|
|
|
errorCode: 0,
|
2018-03-10 05:58:04 +00:00
|
|
|
slug: 'ok',
|
|
|
|
message: _.defaultTo(msg, 'Operation succeeded.')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
generateError (err, complete = true) {
|
|
|
|
const error = {
|
|
|
|
succeeded: false,
|
2019-06-05 02:23:32 +00:00
|
|
|
errorCode: _.isFinite(err.code) ? err.code : 1,
|
2018-03-10 05:58:04 +00:00
|
|
|
slug: err.name,
|
|
|
|
message: err.message || 'An unexpected error occured.'
|
|
|
|
}
|
2018-03-25 02:35:47 +00:00
|
|
|
return (complete) ? { responseResult: error } : error
|
2018-03-09 05:33:43 +00:00
|
|
|
}
|
|
|
|
}
|