Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
3 answers
1k views

Math calculation JavaScript. Am I using Objects correctly? Can I use methods / functions to shorten my code further? Also error logging?

Context- CRM system, front-end form. Requirement- Within a form users have to give a rating to a section based on user inputs, each rating has different weighting. The rating is stored in an option ...
BenDev21's user avatar
2 votes
1 answer
171 views

Command handlers in node.js

Description This javascript code uses tmi.js to listen for chat messages in a Twitch chat and perform certain actions depending on their content. In the sample code ...
Patrick Christie's user avatar
2 votes
1 answer
47 views

error tracking in api endpoint

I have built a simple Nuxt 3 app and have some custom api endpoints. I am currently tracking the user query and response statuses to have some insight when something goes wrong and that the app is ...
wittgenstein's user avatar
0 votes
1 answer
341 views

Google App Script Automation for User Onboarding

Background I am a relatively new developer(> 2 years coding) working as an intern for a smaller company, as part of a now 4 person team. We had two other team members, one our system admin and the ...
RankinJ's user avatar
2 votes
0 answers
295 views

JavaScript proxy for better stack traces from external libraries

I've been using the excellent pg-promise library for a few years now, but my primary irk with it is that the stack traces are sometimes unhelpful. For example, the following test will fail (currently ...
BrDaHa's user avatar
  • 133
6 votes
1 answer
1k views

Implementation of exponential backoff algorithm

You can read about the algorithm here. An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. An example is: Make ...
sg7610's user avatar
  • 368
9 votes
3 answers
3k views

Error solution: Uncaught TypeError

Uncaught TypeError: document.getElementById(...) is null I have a single JavaScript file that is connected to multiple pages. The below snippet is a function that is used for a single page. The above ...
user avatar
1 vote
1 answer
57 views

Handling errors in an input based program

I wrote a program which creates a svg-group that contains several arranged rectangles with passages inbetween to reach all of the rectangles inside of an area selected by the user. Each rectangle ...
IceRevenge's user avatar
2 votes
1 answer
520 views

Blocking requests within Express

Is this the correct way to block requests in Express? app.js ...
shorif2000's user avatar
-1 votes
1 answer
1k views

Try-catch-finally snippet [closed]

Using visual studio I created a snippet which helps me surround my already written or new code into a try-catch-finally block. I use axios for REST so there had to be separate error handling method so ...
Suleman's user avatar
  • 169
4 votes
1 answer
1k views

Node.js http retry do while mechanism

I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array ...
user195155's user avatar
3 votes
0 answers
25 views

A XMLHttp Request in the browser

Building on a previous answer and an attempt to write a comprehensive XMLHttpRequest example that covers all kinds of possible errors and return them to caller ...
Developer's user avatar
  • 205
0 votes
1 answer
131 views

#Error Handling- Propagating errors to calling function.

Im new to javascript programming and i am required to make a web app. Node.js will be used as the js runtime environment. In order to minimize the amount of time needed for debugging as the app ...
nicholas mitchell's user avatar
1 vote
2 answers
400 views

Function to map letters to numbers

I have a method that converts characters to numbers. It expects a single alphabetical character and returns the equivalent number. For example, if A is provided it returns 1, for B it returns 2. If an ...
Ananda's user avatar
  • 111
1 vote
2 answers
112 views

Error handling for a simple 'fetch some data, then save the data' Node function

This is a fairly simple bit of code: ...
dwjohnston's user avatar
  • 1,298
3 votes
0 answers
46 views

Creating chart from data fetched from backend

I have a javascript function written which I think is horrible for multiple reasons (which I have tried to mention in the comments in code below). I want to give it a rewrite following some best ...
anekix's user avatar
  • 161
5 votes
1 answer
207 views

Resource closing in a promise chain

This is some code that fetches a result from a database. It connects, makes a query, processes the query, then has to close the DB (under all possible code paths) and return the result. It seems ...
jfriend00's user avatar
  • 3,948
3 votes
2 answers
4k views

Timeout implementation of fetch

After doing some research on google i didn't find any good info on how to implement timeout with fetch (looks like there are multiple proposals but that's about it so nothing has implemented it). For ...
coding4fun's user avatar
1 vote
2 answers
59 views

Parameter guards for Firebase calls

I have code to ensure parameters existence all over the place. Is there a better way to do it? So that I do not have so many repeated codes inside different functions ...
XYZ's user avatar
  • 167
0 votes
2 answers
1k views

Node.js error handling using merely if else without try catch

I'm confused why you need to use try catch. I made a simply utils like this, and use it on my models' callback. in my utils/error.js ...
alex johanson's user avatar
1 vote
1 answer
180 views

Hello World Node application with error handling

I wrote this simple server in node. Actually my goal is to better understand exception handling best practices in Node. So my question is more specific. Is this code bullet proof to exceptions? Are ...
user avatar
4 votes
1 answer
3k views

AngularJS recursive function call with $timeout

I have created a recursive function call in AngularJS and just wonder if is there a better way to solve this problem? The code works perfectly. My code is the following: ...
Embrioka's user avatar
  • 313
5 votes
1 answer
371 views

An object for passing a chain of errors in JavaScript

I want to pass errors in errors in order to know exactly the chain of causes, but without augmenting or even reading any stack until this becomes really necessary. And this is how I would achieve this:...
borisdiakur's user avatar
4 votes
1 answer
76 views

Takes function and throws exception if passed function doesn't throw an exception

The code below is part of a toy test assertion library I've written. I'm looking for feedback specifically on lines 4 - 9. I'd like to extract them from the ...
Mary Rose Cook's user avatar
1 vote
1 answer
344 views

Logging errors in google analytics

Apart from general JavaScript knowledge, this snippets requires someone who knows how to properly use Google Analytics API. To log errors on my site, I use this code: ...
Tomáš Zato's user avatar
2 votes
0 answers
70 views

Javascript Either

I wrote this up out of necessity, then realized that I actually needed to write it in PHP. Just so I didn't waste the last hour, I'd like a review of it. My concerns: This is my first time using the ...
Carcigenicate's user avatar
3 votes
0 answers
260 views

Keeping error details out of responses (Restify)

I'd like to make sure error details are never sent out in responses from my restify-powered API. The best way to achieve that seemed to be via wrapping server.formatters in another function which ...
Max's user avatar
  • 131
3 votes
1 answer
1k views

Loading a database table using a promise chain

I am creating a util module that I'm using to communicate with a MS-SQL database. I want each public method to return a promise. I started with a private function that executes a DB query and returns ...
TimCodes's user avatar
  • 115
2 votes
1 answer
149 views

Handling success and failure when retrieving product information

I've got an Angular controller where I have two functions that are repeated inside two functions: ...
Jonathan Solorzano's user avatar
2 votes
2 answers
286 views

Handling rejected HTTP responses with status 401

I'm kinda new to javascript and have question about it. Now my practical project is growing a bit bigger. I got the following if else statement. Is it possible to refactor this ? Should i use an use ...
Greg's user avatar
  • 193
0 votes
2 answers
440 views

Concatenating multiple strings from a JSON response

I would like to concatenate a series of strings populated from an XHR response. So, I've chosen to do it like this: ...
Chris's user avatar
  • 9
2 votes
2 answers
73 views

Controller method to validate and save

I have built RESTful web services. The services endpoints have a similar logic: If the input validation succeeds, do a database operation and return the result. If the db operation fails, return the ...
ontk's user avatar
  • 121
1 vote
1 answer
130 views

Logging out using nested promises

Is it OK to do that ? for example, I have my log out service ...
Non's user avatar
  • 183
4 votes
1 answer
80 views

Continuable if error is null

I made a method that I can use to avoid having to handle errors from callbacks. What it does is, call the passed method only if the first argument is null. So essentially it will bypass to the last ...
webjay's user avatar
  • 141
7 votes
1 answer
208 views

LiveDate version 2

LiveDate has the ability to display the current date either by asynchronously fetching the time from a server or by just using the client system date. It's only as ...
Kid Diamond's user avatar
  • 2,591
3 votes
0 answers
155 views

Sourcemap translator service

This is my first attempt to a serious Node.js application, I've tried to follow the async style of Node at my best, but I have several doubts and I am sure that this code can be massively improved. ...
Abaco's user avatar
  • 255
2 votes
1 answer
133 views

Validate IP address and create a registration attempt

I'm a C++/Python developer attempting to learn JavaScript, but I'm struggling to write clean code. I've read that async.waterfall and Promises are two ways to flatten the code a bit, but my ...
Cryo's user avatar
  • 123
0 votes
1 answer
10k views

Sorting products by name or price

Lets preface this by saying that when it comes to javascript, I am a hack. I make what I need happen by cobbling together crappy, inefficient, redundant code. I want to get better. Recently I was ...
user avatar
0 votes
1 answer
346 views

Handling all error conditions on success or failure response

I'm working on a screen where I sent a request and I get response in two types. One is success and contains the below format: ...
user3004356's user avatar
4 votes
2 answers
179 views

Querying MongoDB for information on a collection of books

I have this huge chunk of code. Is there any better to write this code, or am I too paranoid that I check every MongoDB query for error? The logic is here: ...
Tim's user avatar
  • 337
1 vote
3 answers
84 views

Type determined return values

I have the following js code: ...
Dethariel's user avatar
  • 183
3 votes
1 answer
8k views

Mongoose promise & error handling

I search for rails-like way of writing NodeJS code and it's more then hard to find the right way. The code quickly become bloated and unreadable. I would like my code to be as clean as possible. ...
xpepermint's user avatar
11 votes
4 answers
2k views

Writing null-safe code to set form values

I will ask my question using the following example: HTML ...
PM 77-1's user avatar
  • 597
4 votes
1 answer
1k views

If vs try/catch

The following code, written in synchronous Node.js and intended to be used as a shell script, nests a try/catch inside a conditional. Because both the conditional and the try/catch serve a similar ...
user avatar
5 votes
1 answer
433 views

Reading the contents of an XPI file

I wrote this code to list contents of an XPI file and then read the contents in it. I was thinking of these areas of improvement: I put the zr.open in the ...
Noitidart's user avatar
  • 261
3 votes
1 answer
260 views

Seeding a file with fake records - doing concurrent updates

I need to seed a database with user data. When trying to write records to a file using sqlite3 with node, I tried writing the logic in a naive manner, without any error checks - but it was failing ...
saraf's user avatar
  • 131
6 votes
1 answer
262 views

Structuring functions receiving and returning promises?

I keep running into the same pattern with code using promises in javascript. When writing a function which takes a promise and returns a promise, obviously I want to reject the promise I'm returning ...
warp's user avatar
  • 163
4 votes
2 answers
105 views

Writing a user's profile image to disk using nested Node.JS closures

I am writing non-blocking code as it should be in Node.JS. If I want run function A after B I do it using callback. But I find this style guide: Use closures, but don't nest them. Otherwise your ...
Valery's user avatar
  • 361
2 votes
1 answer
400 views

Saving and listing Category model

I have this ExpressJS route for saving and listing Category model. ...
JR Galia's user avatar
  • 349
3 votes
2 answers
120 views

Exceptions for control flow

I just wrote the following javascript (jQeury loaded): ...
MosheK's user avatar
  • 131