This topic was automatically generated from Slack. You can find the original thread here.
Neil Lovelace : Hello Everyone,
Fairly new to the world of javascript, but learning quickly. Anyone have an idea why I’m getting a syntax error on this line? It only occurs when I add the await
Dylan Sather (Pipedream) : Hi , getting used to async / await and asynchronous programming in JS can take a long time even for seasoned JS devs, so no sweat .
Dylan Sather (Pipedream) : would you mind sharing your workflow with dylan@pipedream.com? I can take a look at the Promise warning to see if there’s anywhere else you need to await.
Re: the 401, that suggests the request is unauthorized, so it’s likely the token you’re passing is either invalid, or it’s not being passed correctly. I’d suggest looking at the docs a bit more for that service to confirm you’re indeed forming the request correctly.
Neil Lovelace : Done.
I’m trying to create this on my own - I know that you’ve created a Procore connector already. I have to learn this so I can understand it better for my own benefit.
Neil Lovelace : I figured this part out. Silly mistake on my part.
Next is returning the pro_token variable between steps. I feel like I’m assigning the value properly and I thought I was returning it in the correct place(s), but it continues to be undefined when I try to console.log it.
Dylan Sather (Pipedream) : it’s subtle but I believe you might not be getting the 401 error because the code isn’t even running correctly (if you’re not awaiting the function, Pipedream will just move on to the next step and so you may never make the HTTP request). You’ll want to add the await back in, and hunt down the source of the 401.
I’m not sure with Procore, but most OAuth access tokens have an expiry of ~60 minutes. Is it possible that the token you stored as an environment variable is old, and that’s why it’s failing? That would be my first guess.
Dylan Sather (Pipedream) : Also since it looks like you’re trying to catch that case - get a new token if the old one is expired - you’ll actually want to wrap the initial axios.get call where you check the token within a try / catch statement. You’re never trying to fetch a new token because axios will throw an error if it gets a 401. So you can’t just check for errors in the response like you are. Your code will never reach that point. You essentially want to:
Dylan Sather (Pipedream) : Try to read the axios docs to see how they throw on HTTP errors like this, and read up on try / catch a bit to see how to incorporate that logic into your code