Skip to content

Commit

Permalink
try catch ws json parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Tucsky committed Mar 6, 2024
1 parent 7c351b5 commit 2a885b9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ COPY ecosystem.config.js ${WORKDIR}

EXPOSE ${PORT}

ENV RUNNING_IN_DOCKER true

ENTRYPOINT ["/usr/bin/tini", "--"]
CMD [ "pm2-runtime", "ecosystem.config.js"]
2 changes: 2 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ COPY --from=builder ./ecosystem.config.dev.yaml ${WORKDIR}/

EXPOSE ${PORT}

ENV RUNNING_IN_DOCKER true

CMD [ "pm2-dev", "ecosystem.config.dev.yaml"]
30 changes: 16 additions & 14 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,22 @@ try {

const config = Object.assign(defaultConfig, userSettings, commandSettings)

/* Override config with ENV variables using decamelize + uppercase
(e.g. influxPreheatRange -> INFLUX_PREHEAT_RANGE)
*/

Object.keys(config).forEach(k => {
config_to_env_key = decamelize(k, '_').toUpperCase()
config_env_value = process.env[config_to_env_key]
if (config_env_value) {
config[k] = config_env_value
console.log(
`overriding '${k}' to '${config_env_value}' via env '${config_to_env_key}'`
)
}
})
if (process.env.RUNNING_IN_DOCKER) {
/* Override config with ENV variables using decamelize + uppercase
(e.g. influxPreheatRange -> INFLUX_PREHEAT_RANGE)
*/

Object.keys(config).forEach(k => {
config_to_env_key = decamelize(k, '_').toUpperCase()
config_env_value = process.env[config_to_env_key]
if (config_env_value) {
config[k] = config_env_value
console.log(
`overriding '${k}' to '${config_env_value}' via env '${config_to_env_key}'`
)
}
})
}

/**
* Set Alert service Vapid keys from ENV to config file
Expand Down
22 changes: 13 additions & 9 deletions src/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ class Exchange extends EventEmitter {
}

api.onmessage = event => {
const wasBadData = !this.onMessage(event, api)
try {
const wasBadData = !this.onMessage(event, api)

if (
wasBadData &&
event.data &&
/\b(unrecognized|failure|invalid|error|expired|cannot|exceeded|error|alert|bad|please|warning)\b/.test(
event.data
)
) {
console.error(`[${this.id}] error message intercepted\n`, event.data)
if (
wasBadData &&
event.data &&
/\b(unrecognized|failure|invalid|error|expired|cannot|exceeded|error|alert|bad|please|warning)\b/.test(
event.data
)
) {
console.error(`[${this.id}] error message intercepted\n`, event.data)
}
} catch (error) {
console.error(`[${this.id}] failed to parse ws message\n`, error.message)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ class AlertService extends EventEmitter {
now - this.alertEndpoints[endpoint].timestamp >
config.alertEndpointExpiresAfter
) {
console.warn(
/* console.warn(
`[alert/get] removed expired endpoint (last updated ${ago(
this.alertEndpoints[endpoint].timestamp
)} ago)`
)
) */
delete this.alertEndpoints[endpoint]
}
}
Expand Down

0 comments on commit 2a885b9

Please sign in to comment.