I'm thinking it could have something to do with ex...
# support-questions
h
I'm thinking it could have something to do with express 4. To set headers in express 4: res.set(key,value). But looking at this it seems it tries setting the header with methods res.header and res.setHeader. https://github.com/supertokens/supertokens-node/blob/master/lib/ts/framework/utils.ts
r
Hey @hoffeman this usually happens if you pass in the request object instead of passing in the response object in some function of ours which requires them as the input
it can also happen if you have already sent the response and then you trigger something that causes a header update from our side
h
yes, it is weird since it only happens sometimes. Im thinking it could be when the client is using the refresh token
r
probably not, unless you have overriden the refresh API
it's most like that the response has already been sent
h
true
im also using the SupertokensExceptionFilter from the guide so it should stop propagation if headers have been sent
r
yeaa.. maybe you can see which function call is causing this error?
h
[Nest] 78 - 07/05/2022, 9:56:51 AM ERROR [ExceptionsHandler] Error while setting header with key: front-token and value: eyJ1aWQiOiJkYjZmYWVlNC0zNDU1LTRlYTYtODdjOS04N2M2NjA4MzA0YWYiLCJhdGUiOjE2NTcwMTg2MTExNTEsInVwIjp7InJvbGUiOiJBRE1JTiIsIm9yZ2FuaXphdGlvbklkIjoidGVzdCJ9fQ== rapid-api_1 | Error: Error while setting header with key: front-token and value: eyJ1aWQiOiJkYjZmYWVlNC0zNDU1LTRlYTYtODdjOS04N2M2NjA4MzA0YWYiLCJhdGUiOjE2NTcwMTg2MTExNTEsInVwIjp7InJvbGUiOiJBRE1JTiIsIm9yZ2FuaXphdGlvbklkIjoidGVzdCJ9fQ== rapid-api_1 | at Object.setHeaderForExpressLikeResponse (/usr/src/app/node_modules/supertokens-node/lib/build/framework/utils.js:236:15) rapid-api_1 | at ExpressResponse.setHeader (/usr/src/app/node_modules/supertokens-node/lib/build/framework/express/framework.js:111:21) rapid-api_1 | at Object.setFrontTokenInHeaders (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/cookieAndHeaders.js:73:9) rapid-api_1 | at Object. (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:216:44) rapid-api_1 | at Generator.next () rapid-api_1 | at fulfilled (/usr/src/app/node_modules/supertokens-node/lib/build/recipe/session/recipeImplementation.js:15:36) rapid-api_1 | at processTicksAndRejections (node:internal/process/task_queues:95:5)
this is the only stack trace i get..
i also tried disabling all exceptionfilters
r
Can you upload your code and share it on github?
h
it seems to only happen after i while so im thinking it has something to do when it needs to refresh the token
yea sure, can I invite you? it is a private repo
r
deos this happen when calling the refresh API only?
yea. Invite me to id
rishabhpoddar is my github
h
no it is actually a regular api request
r
@porcellus can help here too
h
i have added you to the repo now
r
ok thanks
h
ignore all the commit messages plz 🙂
r
haha
fair
h
cloud-api/api/common/auth/
thats where the supertoken module is located
r
ok thanks
p
hi
so what I'd check is the kind of error that's caught and rethrown as the "error while setting header"
are you running this locally?
h
yes
let me check
hmm do you have an idea how to check the kind of error in nest?
tried using a catch all but cant the error type
p
oh, I think the easiest way is to just edit
node_modules/supertokens-node/lib/build/framework/utils.js:236:15
🙂
h
TypeError: res.getHeaders is not a function
thats what i initially though. express 4 uses res.set(key, value) for headers
could be that
oh or sorry
its the getHeaders
but that should be .get() in express 4
p
yep
r
we wrap the res object in supertokens to standardise the functions across different frameworks. In our wrapper, we have
getHeaders
as a function.
h
ah ok. any idea how i can continue troubleshooting?
r
let us check
@kakashi_44 see here please
@hoffeman can you please open an issue about this on our github?
we will fix it right away
h
sure
r
thanks
h
if i relogin on the frontend it works again, it is only after being idle and then making a request this happens
any special guidelines i need to follow for the issue?
r
Not really, you can just describe it however you like
In the JS code you modified, can you print out the value of
res
? What does it print?
h
i just reloggedin, probably have to wait a while before the error occurs again 🙂
but ill post here asap
r
right. Can you delete the access token from cookies and then make an API request?
h
y
r
Maybe that will trigger the error
h
nope got a more stuructured error "Access token has expired"
now i got it
not exactly the same though
r
ok. Great! Can you show me what the value of
res
is?
h
there is almost the full res object
the console truncated the first part
if needed i could try to save it as a file
r
right. I am seeing it now
Can you show the full object please?
h
ill try, i think i get a circular json error when JSON.stringiy the object
r
Can you try and log:
Copy code
console.log(res.getHeaders)
console.log(res.get)
h
sure, but note that the error i get now after deleting the cookie is not happening in the same function
but it could probably be related
r
right.
h
undefined [Function: header]
so getHeader and getHeaders is undefined
res.get is a function
r
ok thanks. This is helpful
h
r
thank you!
Hey @hoffeman how can I run the server on my local machine?
h
Hi sorry for late response. Just run npm run dev. Requires docker and docker-compose though
You might also need a dev-account.json in root dir. I think it will start with a dummy
r
Ok thanks
hey @hoffeman i tried to setup a new nestjs project similar to yours and it all works fine. Can we get on a call to debug this on your project?
You can pick a time here: https://supertokens.com/call-user
h
Yes, i booked a time on friday. Did you succeed to start my project or a new scaffold nestjs?
r
Hey! I couldn't get the project you gave us to work, that's why i asked for a call - so we can debug it 🙂
h
👍
n
Hey @hoffeman, Just let us know when you're ready for the call
h
yes 🙂
ok i think i can show you now 🙂
r
cool
h
should we use the old meeting room?