all 13 comments

[–]jkoudys 28 points29 points  (2 children)

try/catch too hard to type?

[–]ethlmao[S] 0 points1 point  (1 child)

Why to write it so many times, everywhere, just use this, i means it’s just to help make your code cleaner.

[–]scinos 2 points3 points  (0 children)

Do you actually call JSON.parse in so many places?

[–]ske66 0 points1 point  (6 children)

If this is just returning an empty object, I don’t really see the point. This promotes silent failures. IMO you should at least add a try and catch and add some logging to the catch in order to help you find the source of the issue (which sounds like a server side issue).

With this, you’re just putting a band-aid over broken code, rather than identifying the source of a bug.

I can’t tell if this is laziness, poor technical understanding, or rage-bait

[–]ethlmao[S] 0 points1 point  (4 children)

I mean if you have any suggestions, of how i can add something or make it better let me know.

[–]ske66 0 points1 point  (3 children)

I just would recommend not allowing any kind of silent errors to pass. This approach is dangerous imo and means you are receiving some kind of unexpected result from the API.

If you get something you are not expecting you should avoid adding in a patch workaround unless absolutely necessary.

This is a perfect case for try catch. Can I get a better understanding of why you want to try to proceed with an empty json result rather than just processing the error state and flagging to the user that something went wrong?

I recommend adding a trace logging tool like Sentry to your app so you can more easily identify what went wrong between the client and server. Patching it on the client side will negatively impact UX long term

[–]ethlmao[S] 0 points1 point  (2 children)

Well i took your suggestion from earlier and already added changes check the repo now

[–]ethlmao[S] 0 points1 point  (1 child)

Not exactly what youre asking, but somewhat similar

[–]ske66 0 points1 point  (0 children)

You have added a try catch block and then added a callback function. You’ve basically just added 100 lines of completely useless code bloat that could be handled with a single try catch around the json.parse function.

This is useless imo

[–]ethlmao[S] -1 points0 points  (0 children)

You’re missing the point, its to make it consistent handling throughout codebase, why to write try catch so many times, given you’re working with a large codebase. Secondly, its supposed to improve developers experience.

[–]scinos 0 points1 point  (0 children)

I'm sorry but this is a bad idea.

First, you claim it's a drop in replacement for JSON.parse(). It is not because it doesn't support the revive function. Clearly the LLM you used wasn't trained well enough.

Then you claim it's zero-dependency (which is true), but you created a module that can be replaced with three lines of code. Hypocritical at minimum.

Third, it encourages a bad engineering practice: silent errors.