« first day (4535 days earlier)      last day (417 days later) » 

1:22 AM
What http status do you send back if you have an error in your code on the server?
Do you just send back status 200 and then the error message?
 
 
2 hours later…
3:37 AM
@1.21gigawatts usually with internal server errors you would return 500 (node.js already does this automatically) but for client errors 403 seems the most likely one for errors.
Or alternatives are: 502 for server, 400 for client.
 
 
2 hours later…
6:08 AM
@1.21gigawatts It's 500 Internal Server Error. Also, I don't think I've ever written code to send such a status - it's always automatic when the exception bubbles up to the endpoint and it hasn't been handled. What I have written is a try/catch in an endpoint to throw a different user-facing exception. Something like:
try {
	return doStuff();
} catch (NoBananaException e) {
	throw new UserException(e.message);
}
This would at least send a uniform object back rather than whatever the original exception happens to be.
@ParkingMaster 502 is Bad Gateway. Don't return it for server errors, it's for when the backend can't be reached due to something else not working in the network before reaching the backend. Usually a proxy or similar.
@ParkingMaster Also 403 is Forbidden. Again - not appropriate for errors. It's when a user request is denied on the grounds of permissions. It means you're not allowed to do this. Note that it's different from 401: 403 means "I know who the user is and I do not allow them to do the action" while 401 means "I do not know who the user is because they've not authenticated themselves successfully and I need that in order to determine whether to allow the action"
With examples:

- "Hi, server, I want to do X. I'm Alice and here is my password" -> "The password you entered does not match what I have: 401"
- "Hi, server, I want to do X. I'm Bob and here is my password" -> "The password you entered is correct but Bot is not allowed to do X: 403"
- "Hi, server, I want to do X. I'm Carol and here is my password" -> "The password you entered is correct and Carol is allowed to do X: 200"
 
 
3 hours later…
9:14 AM
@All Im looking to write a single page nodejs script, to update some one time data and some third party api calls through this script.
Im trying to have one file and trying to connect to my mongodb.
Can I connect to mongo with any default node module.
mongoose or mongodb module would need module installation, which we don't want to do
 
 
2 hours later…
11:10 AM
It doesn't really relate to JS, but I really don't know where else to go. I've been stuck with this for days on end. You're front guys anyway. My Tomcat (9 or 10, doesn't matter) keeps on throwing that 404 at me. The requests are handled, the views do exist – and yet it doesn't work
It's the same with any of these projects (they are for educational purposes only, don't expect much): github.com/NadChel/CRUD_user, github.com/NadChel/rest_project, github.com/NadChel/spring_security. Any ideas?
 
I'd suggest trying the Java room. I personally have used Tomcat but never actually configured it from scratch (or "configured it" more generally. I've only done small changes), so I'm not totally sure what might be going wrong.
 
11:28 AM
why doesnt pnpm link work with package that only exports ts?
yalc works fine, and so does npm
 
 
2 hours later…
1:35 PM
@VLAZ good explanation. But I actually said 502 was an alternative in case the OP didn’t intend to use 500. And about the 403 - Some webpages misuse 403 when there is and error on the client or server. Since everyone misuses it anyway - I’d think it’s ok to use it for errors. Otherwise, 400 is the best way to go. 500 and 400 seem to be the best options.
 
2:32 PM
An alternative would be to make up your own 5XX code. For example like Microsoft do when they throw something like 500.1 which is like a "subtype" of a 500. It's not appropriate to throw a completely wrong code. A 502 has specific meaning and anybody seeing it would assume it means what it means. Not that it means something different. If it's just you who is throwing and consuming the error, you could just go with a 200 and an error field.
Also "some do it wrong" is a terrible justification for why you should do something wrong.
Especially when it's trivial to not be wrong. By just using a correct error code.
 
 
2 hours later…
4:26 PM
any lib for encoding jwt?
https://github.com/auth0/jwt-decode/issues?q=is%3Aissue+is%3Aopen+encode
just found decode here
 
4:41 PM
Encoding? I'm not really ssure why you'd be doing that "by hand". You should have a library/service/whatever that issues them to you. If you are building a thing that issues them, then you just need to generate the three parts to a JWT and encode each as base64. Then join with a dot.
 
i mean, using a lib for it wouldn't be doing it by hand
 
Oh and drop the 0-2 = signs used for padding by base64
@KevinB "by hand" as in, you somehow have the header, payload, and signature without those being encoded.
function encodeJWT({header, payload, signature}) {
	return [header, payload, signature]
		.map(x => btoa(JSON.stringify(x)).replace(/=+$/, ""))
		.join(".")
}
I mean, here is the "library" you need for that.
There are libraries listed on the jwt.io site: jwt.io/libraries
Hmm, actually the code above is not quite enough. I didn't take into account that the signature is ran over the encoded first two parts. I guess have a look at the libraries on jwt.io, then.
 
which one on encode on browser?
i need it for vitest jwt generation
ie es6 import friendly
 
scroll to the JS section in the libraries and check them.
 
 
2 hours later…
6:58 PM
 

« first day (4535 days earlier)      last day (417 days later) »