Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
check config for existing env vars + safer axios error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ildella committed Jul 27, 2023
1 parent 88b5fab commit ad51f4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lnd/lnd-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,27 @@ const createWs = ({
headers: {'Grpc-Metadata-Macaroon': macaroon},
})

const createHttp = ({baseUrl, cert, macaroon}) => httpJsonClient({
const create = ({baseUrl, cert, macaroon}) => httpJsonClient({
baseURL: `https://${baseUrl}`,
httpsAgent: new https.Agent({rejectUnauthorized: false, cert}),
headers: {'Grpc-Metadata-macaroon': macaroon},
})

const {parseAxiosError} = require('../errors')

const createHttp = params => {
const instance = create(params)
instance.interceptors.response.use(
response => response,
error => {
const parsed = parseAxiosError(error)
// console.log(error.response.data)
return Promise.reject(parsed)
}
)
return instance
}

module.exports = {
createWs,
createHttp,
Expand Down
3 changes: 3 additions & 0 deletions lnd/lnd-env-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module.exports = curry((future, {
}) => {
const baseUrl = `${host}:${port}`
const macaroon = process.env[`LND_${macaroonType.toUpperCase()}_MACAROON`]
if (!macaroon) throw new Error('Configuration error: mising macaroon env var')
const hexCertificate = process.env.LND_TLS_CERT
if (!hexCertificate) throw new Error('Configuration error: mising cert env var')
console.log({macaroon, hexCertificate})
const cert = Buffer.from(hexCertificate, 'hex').toString('utf8')
return {macaroon, cert, baseUrl}
})

0 comments on commit ad51f4c

Please sign in to comment.