diff --git a/command-handler/src/util/axios-error-handler.js b/command-handler/src/util/axios-error-handler.js new file mode 100644 index 0000000..cda3db3 --- /dev/null +++ b/command-handler/src/util/axios-error-handler.js @@ -0,0 +1,9 @@ +export default function axiosError(e) { + const errorObj = { + data: e.response.data, + status: e.response.status, + stackTrace: e.stack + + } + return errorObj; +} \ No newline at end of file diff --git a/command-handler/src/util/get-devices-info.js b/command-handler/src/util/get-devices-info.js index c71211c..93b2d8f 100644 --- a/command-handler/src/util/get-devices-info.js +++ b/command-handler/src/util/get-devices-info.js @@ -1,6 +1,9 @@ import 'dotenv/config'; import axios from 'axios'; -import log from './logger.js'; +import logger from './logger.js'; +import axiosError from './axios-error-handler.js'; + +const log = logger(); export default async function getDevices(serverName = null) { //get all the devices from tailscale @@ -10,7 +13,7 @@ export default async function getDevices(serverName = null) { } }) .catch(error => { - log.error('Failed to get devices from tailscale', error); + log.error('Failed to get devices from tailscale', axiosError(error)); }); //loop through the devices and get a devideId, and deviceIp diff --git a/command-handler/src/util/get-servers.js b/command-handler/src/util/get-servers.js index 64117b8..8cc64c2 100644 --- a/command-handler/src/util/get-servers.js +++ b/command-handler/src/util/get-servers.js @@ -1,6 +1,9 @@ import 'dotenv/config'; import axios from 'axios'; -import log from './logger.js'; +import axiosError from './axios-error-handler.js'; +import logger from './logger.js'; + +const log = logger(); export default async function getServer() { const data = await axios.get('https://api.hetzner.cloud/v1/servers', { @@ -9,7 +12,7 @@ export default async function getServer() { } }) .catch(error => { - log.error('Failed to get servers from hetzner', error); + log.error('Failed to get servers from hetzner', axiosError(error)); }); return data; diff --git a/command-handler/src/util/hetzner-servers.js b/command-handler/src/util/hetzner-servers.js index 9a86405..d031031 100644 --- a/command-handler/src/util/hetzner-servers.js +++ b/command-handler/src/util/hetzner-servers.js @@ -1,11 +1,14 @@ -import log from './logger.js'; +import logger from './logger.js'; import axios from 'axios'; import 'dotenv/config'; import formatUser from './format-user.js'; import getDevices from './get-devices-info.js'; import getServer from './get-servers.js'; +import axiosError from './axios-error-handler.js'; import { uniqueNamesGenerator, colors, animals } from 'unique-names-generator'; +const log = logger(); + const delay = (ms) => { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -58,7 +61,7 @@ export default { } }) .catch(error => { - log.error('There was an error creating the server', error); + log.error('There was an error creating the server', axiosError(error)); }); //set 2 minute delay @@ -80,7 +83,7 @@ export default { } }) .catch(error => { - console.error('There was an error setting tags in tailscale', error); + console.error('There was an error setting tags in tailscale', axiosError(error)); }); //return info for tailscale @@ -115,7 +118,7 @@ export default { } }) .catch(error => { - log.error('Failed to delete device in tailscale', error); + log.error('Failed to delete device in tailscale', axiosError(error)); }); //delete server from hetzner @@ -125,7 +128,7 @@ export default { } }) .catch(error => { - log.error('Failed to delete the server in hetzner', error); + log.error('Failed to delete the server in hetzner', axiosError(error)); }); app.client.chat.postEphemeral({ @@ -208,7 +211,7 @@ export default { } }) .catch(error => { - log.error('Error starting the server', error); + log.error('Error starting the server', axiosError(error)); app.client.chat.postEphemeral({ channel: `${body.channel.id}`, user: `${body.user.id}`, @@ -232,7 +235,7 @@ export default { } }) .catch(error => { - log.error('Error stopping the server', error); + log.error('Error stopping the server', axiosError(error)); app.client.chat.postEphemeral({ channel: `${body.channel.id}`, user: `${body.user.id}`,