Throw error if env var are empty

pull/2355/head
Jérémy Rialland 2022-10-24 19:38:20 +02:00 committed by Jérémy Rialland
parent 1356c8d157
commit 845ba27667
2 changed files with 22 additions and 10 deletions

View File

@ -1,11 +1,15 @@
import type { MattermostSendMessage } from './mattermost.js'
if (!process.env.MONGO_URL) {
throw new Error('MONGO_URL env var is empty')
throw new Error('Empty MONGO_URL env var')
}
if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) {
throw new Error('Empty env var CLIENT_ID or CLIENT_SECRET')
if (!process.env.CLIENT_ID) {
throw new Error('Empty CLIENT_ID env var')
}
if (!process.env.CLIENT_SECRET) {
throw new Error('Empty CLIENT_SECRET env var')
}
export const PORT = process.env.PORT || 4000

View File

@ -1,5 +1,19 @@
import Crisp from 'crisp-api'
const CRISP_API_IDENTIFIER = process.env.CRISP_API_IDENTIFIER
const CRISP_API_KEY = process.env.CRISP_API_KEY
const WEBSITE_ID = process.env.CRISP_WEBSITE_ID
if (!CRISP_API_IDENTIFIER) {
throw new Error('Empty CRISP_API_IDENTIFIER env var')
}
if (!CRISP_API_KEY) {
throw new Error('Empty CRISP_API_KEY env var')
}
if (!WEBSITE_ID) {
throw new Error('Empty WEBSITE_ID env var')
}
export type BodyType = {
subject: string
message: string
@ -48,13 +62,7 @@ export const sendCrispMessage = async (body: BodyType) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const CrispClient = new Crisp() as unknown as CrispType
CrispClient.authenticateTier(
'plugin',
process.env.CRISP_API_IDENTIFIER,
process.env.CRISP_API_KEY
)
const WEBSITE_ID = process.env.CRISP_WEBSITE_ID as string
CrispClient.authenticateTier('plugin', CRISP_API_IDENTIFIER, CRISP_API_KEY)
const result = await CrispClient.website.createNewConversation(WEBSITE_ID)