import axios, { AxiosError } from 'axios'; import serversideConfig from '../../serversideConfig'; import https from 'https'; let productionOrderTemplates = []; let errorMsg = ''; export default defineEventHandler(async (event) => { if (event.path.startsWith("/api/getAllProductionOrderTemplates")) { const agent = new https.Agent({ rejectUnauthorized: false, }); const axiosInstance = axios.create({ headers: { 'Content-Type': 'application/json', Accept: "*", }, httpsAgent: agent }); // get all production order templates object from backend try { let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrders`); productionOrderTemplates = res.data; } catch (err) { if (axios.isAxiosError(err)) { const axiosError = err as AxiosError; if (axiosError.response) { // Axios error console.error(axiosError.response.data.message); errorMsg = axiosError.response.data.message; } else if (axiosError.request) { // If error was caused by the request console.error(axiosError.request); } else { // Other errors console.error('Error', axiosError.message); } } else { // No AxiosError console.error('Error', err); } } } }) export { productionOrderTemplates, errorMsg };