42 lines
961 B
JavaScript
42 lines
961 B
JavaScript
import axios from "axios";
|
|
|
|
const post = async (path, data, onError) => {
|
|
return axios.post(`${import.meta.env.VITE_API_ADDR}${path}`, data)
|
|
.then(r => r.data)
|
|
.catch(error => {
|
|
onError && onError(error)
|
|
console.error('Error post request:', error)
|
|
})
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {String} path
|
|
* @returns {Promise<axios.AxiosResponse<Array | Object> | void>}
|
|
*/
|
|
const get = async (path) => {
|
|
return axios.get(`${import.meta.env.VITE_API_ADDR}${path}`)
|
|
.catch(error => {
|
|
console.error('Error post request:', error)
|
|
})
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @param {Object} data
|
|
* @param {Function} onError
|
|
* @returns {Promise<axios.AxiosResponse<any> | void>}
|
|
*/
|
|
const scand_post = async (data, onError) => {
|
|
return axios.post(`${import.meta.env.VITE_SCAND_API_URL}`, data)
|
|
.then(r => r.data)
|
|
.catch(error => {
|
|
onError && onError(error)
|
|
console.error('Error post request:', error)
|
|
})
|
|
}
|
|
|
|
|
|
export {get, post, scand_post}
|