Skip to content

Commit

Permalink
Eh, just use .then() + .catch() instead of callbackify
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanblock committed Oct 12, 2023
1 parent eba7bc3 commit f779d7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
29 changes: 14 additions & 15 deletions src/discovery/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
let { callbackify } = require('util')
let { getAwsClient, useAWS } = require('../lib')

/**
Expand Down Expand Up @@ -43,18 +42,8 @@ module.exports = function lookup (callback) {
if (err) callback(err)
else {
let Path = `/${stack || toLogicalID(`${app}-${env}`)}`
let GetParametersByPath = callbackify(client.ssm.GetParametersByPath)
GetParametersByPath({ Path, paginate: true }, function done (err, result) {
if (err && local &&
err.message.includes('Inaccessible host') &&
err.message.includes('localhost')) {
let msg = 'Sandbox internal services are unavailable, please ensure Sandbox is running'
callback(ReferenceError(msg))
}
else if (err) {
callback(err)
}
else {
client.ssm.GetParametersByPath({ Path, paginate: true })
.then(result => {
let services = result.Parameters.reduce((a, b) => {
let hierarchy = b.Name.split('/')
hierarchy.shift() // leading slash
Expand All @@ -74,8 +63,18 @@ module.exports = function lookup (callback) {
return a
}, {})
callback(null, services)
}
})
})
.catch(err => {
if (err && local &&
err.message.includes('Inaccessible host') &&
err.message.includes('localhost')) {
let msg = 'Sandbox internal services are unavailable, please ensure Sandbox is running'
callback(ReferenceError(msg))
}
else {
callback(err)
}
})
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let isNode18 = Number(process.version.replace('v', '').split('.')[0]) >= 18
let nonLocalEnvs = [ 'staging', 'production' ]

function getAwsClient (params, callback) {
let { callbackify } = require('util')
let _awsLite = require('@aws-lite/client')
let awsLite = callbackify(_awsLite)
awsLite(params, callback)
let awsLite = require('@aws-lite/client')
awsLite(params)
.then(client => callback(null, client))
.catch(callback)
}

function useAWS () {
Expand Down

0 comments on commit f779d7c

Please sign in to comment.