Skip to content

Commit

Permalink
feat(helpers): add some comments 💡
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 20, 2019
1 parent 32944bd commit 8f6f728
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 18 additions & 13 deletions lib/helpers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@
const path = require('path');

const config = require(path.resolve('./config'));
// const AppError = require(path.resolve('./lib/helpers/AppError'));


/**
* Error Handling
*/
// exports.throwError = (code, errorType, errorMessage) => (error) => {
// if (!error) error = new AppError(errorMessage || 'Default Error');
// error.code = code;
// error.errorType = errorType;
// throw error;
// };

/**
* errors messages generation
* @desc Function to parse error message
* @param {Object} err
* @return {String} message
*/
const getUniqueMessage = (err) => {
let output;
Expand All @@ -44,6 +34,11 @@ const getUniqueMessage = (err) => {
return output;
};

/**
* @desc Function to get error message from specific code
* @param {Object} err
* @return {String} message
*/
const getMessageFromCode = (err) => {
let output;
switch (err.code) {
Expand All @@ -66,6 +61,11 @@ const getMessageFromCode = (err) => {
return output;
};

/**
* @desc Function to map an array of errors
* @param {Object} err
* @return {String} message
*/
const getError = (err) => {
if (err instanceof Array) return err.errors;
let output = '';
Expand All @@ -78,6 +78,11 @@ const getError = (err) => {
return output;
};

/**
* @desc Function to route error to specific actio in order to get clean result for api
* @param {Object} err
* @return {String} message
*/
exports.getMessage = (err) => {
let output = '';
if (err.code) output = getMessageFromCode(err);
Expand Down
4 changes: 0 additions & 4 deletions lib/helpers/responses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Defaults answers
*/

/**
* @desc Function res success
* @param {Object} res - Express response object
Expand Down

0 comments on commit 8f6f728

Please sign in to comment.