Skip to content

Instantly share code, notes, and snippets.

@jesuscast
Last active March 14, 2020 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesuscast/2a0a8852706a82242815aa0dd6ade684 to your computer and use it in GitHub Desktop.
Save jesuscast/2a0a8852706a82242815aa0dd6ade684 to your computer and use it in GitHub Desktop.
const axios = require('axios');
async function sendGetRequest(url, secretKey) {
return await axios({
method: 'get',
url: url,
timeout: 5000,
headers: {
'Authorization': secretKey,
'Accept': 'application/json'
}
})
.catch(function (error) {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
} else {
console.log('Error', error.message);
}
console.log(error.config);
return error;
})
// Request was successful
.then(function (response) {
return response.data;
})
}
module.exports.sendGetRequest = sendGetRequest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment