RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined Forge App - node.js

I am building a 3-legged OAuth Forge application using Visual Studio Code and Node.js. Once I start debugging, the server is listening on http://localhost:3000, but after signing in, I am getting this error message and cannot see Forge Viewer. What is the reason?
Error screenshot

The error you're seeing is most likely a "side effect" of another issue in your code. It looks like the server code is failing for some reason, and when the server tries to send back the generic error response to the client, it does not know what status code to include in the response.
Consider stepping through the authentication code in your Node.js server to narrow down the actual code that's causing the issue.

Related

Node.js Server Response Error sometime (on High load)

The nodejs server response error message on high load.
Some of the errors are:
Http failure response for (api url):0 Unknown Error and cors error. On the browser console.
On Android side the error is unexpected end of stream on Connection {api url:80, proxy=Direct hostaddress=apiurl/serverip:80 cipherSuite=none protocol=http/1.1
We have 16 GB ram 4vCPUs aws instance
nginx rever proxy to loadbalance between 4 instance of node (created through pm2), ip_hash (as we are using socketio)
while looking through the web some suggestions were "Its cors error", "it server side error, contact the backend team"
for cors We am using cors package from npm. app.use(cors()). I am looking for the server side fixation. we are using express.
since the website and app works perfectly while its working, and we get cors error during the problem. it may not be the cors error. during the high load, we get the error instantly, not time out error.
We could not figure out the issue. any suggestions?
Update: Since there are voting going on to close this, I may not get the answer, but here are some errors, Please note that the app and website (angular) works fine but got these error during pick hours, I expect timeout or node to stop, but not these errors so, thought something is wrong.
Update2: While looking though the nginx error log, we get this error.
2021/03/09 17:10:25 [alert] 1058#1058: *2946806 768 worker_connections are not enough while connecting to upstream, client: 120.xx.xxx.114, server: api.mydomain.com, request: "GET /Image-1611905660330.jpg HTTP/1.1", upstream: "http://127.0.0.1:8000/Image-1611905660330.jpg", host: "api.mydomain.com"
Update 3: Looking for the above error, found suggestion that, we need to increase worker_connections, so we update it on /etc/nginx/nginx.conf;. Now we get error *2908 socket() failed (24: Too many open files) while connecting to upstream,
Update 4: Adding worker_rlimit_nofile 20000; to the /etc/nginx/nginx.conf seems to fix the error on update 3.
The cors error is emit by the browser, not the server. server just gives browser cors policy response. Whether it should be treated as error or not is decided by the browser itself.
I'm not android developer, but i think some of your problem is made by misused request from android client, not server.
Android connect Node.js REST unexpeceed end of stream
java.io.IOException: unexpected end of stream on Connection in android

Server Side JS SDK fails to flag user

I have a webhook that runs on message save and message update. I do some basic bad word filtering. I can update the message to filter out bad words. However, when I attempt to flag the message, I get an error. Has anyone seen anything like this? How have you worked around it?
The code:
client.flagMessage(message.id).then(r => console.log('flagged message', r))
I have verified that client works as I am able to update the message with client in the same Promise.all() call.
The error:
Flag failed with error: "either user or user_id must be provided when using server side auth."
Version:
"stream-chat": "^1.7.4"
The docs:
https://getstream.io/chat/docs_rest/#flag
https://github.com/GetStream/stream-chat-js/blob/master/src/client.js#L1227
It seems very similar to this closed issue:
https://github.com/GetStream/stream-chat-js/issues/113
This might not be a proper answer but definitely is a resolution for your problem.
If setUser is called on the client then server will be able to get the flagging user from the JWT (client side auth) but in server side auth, there is no user passed to server so you get the expected error message.
You check REST docs and as seen, server supports it where JS client lacks this server side support. This a missing feature bug from JS client. It's reported to be extended as soon as possible.

Why might a nodeJS API work locally but fail in production?

An API method I've been using without problems on localhost:3000/userinfo suddenly gives an "Empty Reply From Server" when I upload that same code to my web server and send a POST request to myserver.com:3000/userinfo.
Even more strange is that if the JSON returned by user info does not contain an array of objects, there is no error locally or remotely.
I don't know how much detail will be useful, and how much will just clutter this question. This one is especially strange so I'd like to approach it very generally. In other words, I don't think I'm missing a semi colon this time because the API function works perfectly when run on a local server.
So without a whole lot of detail, the only thing I can suggest here is make sure your ports are correct. You said 4200 locally but its 3000 on your server? The error you're getting also suggests ( I'm assuming cURL? ) that it couldn't connect at all to your server, which furthers my hypothesis.
Alternatively, there could be an error in your API and its "crashing" without logging anything, which would also cause an empty reply error.
Be sure to capture unhandled exceptions using process events to log out errors!
https://nodejs.org/dist/latest-v10.x/docs/api/process.html#process_process_events
process.on('uncaughtException', function (error) {
console.error("GOT UNCAUGHT EXECPTION!", error)
process.exit(1);
})

Xirsys turn server fails to connect and PeerServer crashes

My WebRTC application is working but sometimes when I try to call from other machines, iceServerConnectionState gets disconnected. Also, my peer server gets crashed by showing error:
SyntaxError: Unexpected end of JSON input
I am using Xirsys for stun/turn and running a custom peer server built-in Nodejs. Can anyone tell what can be the reason and how to solve it?
Thanks in advance.

How to handle errors in node.js

I know that in node, I can use process.on('UncaughtException',evtHandlerFunction(){/*code*/}); but how do I go about handling errors "properly"? Like, whenever there's an error, send out a status code 500 on the current response stream of the request that the error occured when responding to and tell the user there was a problem. But I can't seem to figure out a good way to do this. How would I go about figuring out what the "current response stream" is, for example? I just want a concept of how to do this, I don't necessarily need code. Sorry if I was unclear, please post a comment if you don't understand.
it totally depends on what kind of errors u want to handle.....
server errors can be http errors, socket errors, net errors etc.
each of these modules have an error handling code
eg:
a socket server object has:
socket.on('error',function(err)
{
//code to handle
});
check out the detailed doc on site nodejs.org
then u can use the response object as:
response.writeHead('500',{'Content_type':'text/plain'});
response.end('Your Error Message');
'your error message' will be the responseText for the client browser

Resources