/* eslint-disable no-console */ import fetch from 'node-fetch' import { sendSlackMessage } from './slackMessage' import { URLs } from './types' const fetchTestNoAuth = async (url: string) => { try { const response = await fetch(url, { method: 'POST', body: JSON.stringify({ name: 'Core Test No Authentication Endpoint', version: '1.0.0', query: 'Core_TestNoAuthentication', data: { someKey: 'Some Value', }, results: { name: 'results', }, auth: null, }), }) return response.json() } catch (err) { throw new Error(err.message) } } export const ping = async (urls: URLs) => { try { const data = await fetchTestNoAuth(urls.httpUrl) if (!data.success) { const text = `${urls.service} SERVICE ISSUE.. :dead: *${urls.awsUrl}* :skull: :dead: \n Not Success` console.log('SERVER IS DOWN', JSON.stringify(urls.httpUrl)) await sendSlackMessage(urls, data, text) return { success: false, urls } } return { success: true, urls } } catch (err) { console.log(err) const text = `${urls.service} SERVICE HTTP ERROR.. :dead: *${urls.awsUrl}* :skull: :dead:` await sendSlackMessage(urls, err, text) console.error(`ERROR:::::: Something went wrong for : ${urls.httpUrl}`, JSON.stringify(err)) return { success: false, urls } } }