Last active
March 14, 2020 20:32
-
-
Save jesuscast/2a0a8852706a82242815aa0dd6ade684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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