Dylan Sather (Pipedream) : thanks. Refresh once more and clear state one more time?
Neil Lovelace : Done and done.
Dylan Sather (Pipedream) : I didn’t immediately see it until I added some more logging, but you’ve got an extra layer of { headers: { ... }
inside of the AXIOS_HDR
function. You return:
{headers:{'Authorization':`Bearer ${token}`,'Content-Type':'application/json'}};
When you need to just return:
{'Authorization':`Bearer ${token}`,'Content-Type':'application/json'};
Does that make sense why that’s causing an issue?
Neil Lovelace : It looks straight forward, but, it works for all of my other calls. Why is this one breaking?
Neil Lovelace : Inside of Axios, I could have sworn that it requires I list the custom headers object like this.
Dylan Sather (Pipedream) : do you see how you’re already defining the headers
property inside of your HTTP request?
await AXIOS({
...
headers: AXIOS_HDR(token)
});
So the way you had the code, you’re saying:
headers: {
headers: {
// your headers here
}
}
Dylan Sather (Pipedream) : when you only need one level
Dylan Sather (Pipedream) : ```
headers: {
// your headers here
}
Neil Lovelace : Gotcha. That makes sense.
Neil Lovelace : So I should change that in the rest of my code too.
Dylan Sather (Pipedream) : here’s how I troubleshot this: anytime you’re making an HTTP request with axios
, you can do something like this:
this.response = await AXIOS({
url: `${PD_BASEURL}/public/v1/documents/${doc_id}/download`,
method: 'GET',
responseType: 'stream',
validateStatus: () => true, // this is important
headers: AXIOS_HDR(token)
});
That exports the axios
response object in this.response
. If you dig into the config
property of this.response
, you can see the final headers axios sent with the request. That’s where I saw the double level:
Neil Lovelace : I just looked at that too.
Dylan Sather (Pipedream) : the extra line - validateStatus: () => true
- ensures axios
doesn’t throw an error on any HTTP 4XX / 5XX error, and instead stores the response for us to examine
Neil Lovelace : Awesome. I saw where you added that line. I’m going to remember that one.
Neil Lovelace : Am I free to go and make edits now? I didn’t want to mess up anything if you were still making edits.
Dylan Sather (Pipedream) : you are all good now
Neil Lovelace : HUUUGE Thanks Dylan. I owe you something. Is there a way to send digital gift cards thru Slack?
Dylan Sather (Pipedream) : Haha you don’t need to worry about that. We do have a Professional plan, though .
By the way, once you get past the 401 issue, you may still see the warning about failing to await all promises, but it might be a false positive.
I’d recommend trying to list the file in the next step of your workflow to see if it’s available in /tmp
. If it is, you are probably OK given your current code.
Neil Lovelace : You’ve gone above and beyond and it is truly appreciated. One day I hope to take off the training wheels.
Neil Lovelace : - I’m pulling my hair out here.
I’ve figured out that the issue isn’t my download code. My code is failing prior to that. I’m getting a message that my token is invalid. How can that be when it is being checked or issued immediately prior to making a call?
Would you mind looking at this code block one more time with me?