const fsPromises = require("fs/promises");
const fs = require('fs')
import axios from 'axios';
import * as https from "https";

const endPointQuery = async (url: string, data: any) => {

    let response: any = null

    try {

        response = await axios.post(url, data);

        console.log(`TEST URL CLIENT POST ROUTE: ${url} | STATUS CODE: ${response.status}`);


    } catch (err: any) {

        if (err.response) {
            // The client was given an error response (5xx, 4xx)
            // console.log('err.response: ', err.response)
            console.log('err.response: ', err.response)

            // return { data: err.response.data, status: err.response.status }

        } else if (err.request) {
            // The client never received a response, and the request was never left
            console.log('err.request: ', err.request)
        } else {
            // Anything else
            console.error(`Erro ao consultar endpoint ${url}: ${err}`);
        }
    }

    return response

}

export default endPointQuery;