Skip to content

Commit

Permalink
[#74] Refactored now-unnecessarily-complex function 🍃
Browse files Browse the repository at this point in the history
  • Loading branch information
todofixthis committed Sep 2, 2019
1 parent b1062a2 commit 7914938
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ module.exports = function getVariableAccessors (container, varName, defValue) {
let isBase64 = false

/**
* Generate a function to throw an error
* Throw an error with a consistent type/format.
* @param {String} value
*/
function generateRaiseError (value) {
return function _raiseError (msg) {
throw new EnvVarError(`"${varName}" ${msg}, but was "${value}"`)
}
function raiseError (value, msg) {
throw new EnvVarError(`"${varName}" ${msg}, but was "${value}"`)
}

/**
Expand All @@ -43,7 +41,7 @@ module.exports = function getVariableAccessors (container, varName, defValue) {

if (isBase64) {
if (!value.match(base64Regex)) {
generateRaiseError(value)('should be a valid base64 string if using convertFromBase64')
raiseError(value, 'should be a valid base64 string if using convertFromBase64')
}

value = Buffer.from(value, 'base64').toString()
Expand All @@ -57,7 +55,7 @@ module.exports = function getVariableAccessors (container, varName, defValue) {
args
)
} catch (error) {
generateRaiseError(value)(error.message)
raiseError(value, error.message)
}
}
}
Expand Down

0 comments on commit 7914938

Please sign in to comment.