You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
597 B
31 lines
597 B
import axios from 'axios'; |
|
import { envVars } from './config.js'; |
|
import { logger } from './utils.js'; |
|
|
|
const config = { |
|
baseURL: envVars.BASE_URL, |
|
headers: { authorization: `Bearer ${envVars.TOKEN}` }, |
|
}; |
|
|
|
const axiosWrapper = async ({ |
|
method, |
|
url, |
|
payload, |
|
responseType = 'json', |
|
}) => { |
|
try { |
|
const result = await axios({ |
|
method, |
|
url, |
|
...config, |
|
data: { ...payload }, |
|
responseType, |
|
}); |
|
return result; |
|
} catch (error) { |
|
logger({ type: 'error', msg: 'axios has run into trouble' }); |
|
return error; |
|
} |
|
}; |
|
|
|
export { axiosWrapper };
|
|
|