You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
507 B

  1. const _ = require('lodash')
  2. module.exports = {
  3. generateSuccess (msg) {
  4. return {
  5. succeeded: true,
  6. errorCode: 0,
  7. slug: 'ok',
  8. message: _.defaultTo(msg, 'Operation succeeded.')
  9. }
  10. },
  11. generateError (err, complete = true) {
  12. const error = {
  13. succeeded: false,
  14. errorCode: _.isFinite(err.code) ? err.code : 1,
  15. slug: err.name,
  16. message: err.message || 'An unexpected error occured.'
  17. }
  18. return (complete) ? { responseResult: error } : error
  19. }
  20. }