Skip to content

Commit

Permalink
fix: fix server crash on start - change slackAlertsWebhook config for…
Browse files Browse the repository at this point in the history
…mat and default value.
  • Loading branch information
yaroslav-fedyshyn-nordwhale committed Jul 23, 2020
1 parent 4f2270e commit da94c75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/imports/slack.js
Expand Up @@ -3,10 +3,13 @@ import Config from '../server/server.config'
import logger from '../imports/logger'

const log = logger.child({ from: 'slack' })

export const sendSlackAlert = async json => {
if (Config.slackAlertsWebhook == null) return
if (!Config.slackAlertsWebhook) return

const { env, version, network } = Config
const text = JSON.stringify({ text: JSON.stringify({ ...json, env, version, network }) })

try {
const res = await fetch(Config.slackAlertsWebhook, {
method: 'POST',
Expand All @@ -16,6 +19,7 @@ export const sendSlackAlert = async json => {
},
body: text
})

log.info('slack alert sent:', { res: await res.text(), json })
} catch (error) {
log.error('failed sending slack alert:', error.message, error, { json })
Expand Down
4 changes: 2 additions & 2 deletions src/server/server.config.js
Expand Up @@ -494,8 +494,8 @@ const conf = convict({
},
slackAlertsWebhook: {
doc: 'secret url for sending alerts to some channel',
format: 'url',
default: null,
format: String,
default: '',
env: 'SLACK_ALERTS_WEBHOOK'
}
})
Expand Down

0 comments on commit da94c75

Please sign in to comment.