A commitment was formulated within a handler but failed to be returned from it

After a user clicks on the button (#lfdsubmit), it triggers the function (LFD_SearchContainer()) which is expected to return a promise. However, errors are occurring at

LFD_SearchContainer('EISU1870725')
.then(container => {
  ST2.db2(container);
})

What could be going wrong here? Code: (don't rely solely on the commented out parts for guidance -- some of them might not be up to date)

function LFDTrack () {

function LFD_SearchContainer(requestedContainer) {
    return new Promise((resolve, reject) => {
        let lfd_scanparams = { TableName: 'lfd_table1' }
        db.scan(lfd_scanparams, (err, containers) => {
            if (err) {
                reject(err);
            } else {
                containers = containers.Items;

                let requestedContainers = []; // a different variable from the argument

                let containerObject; // this will be the resolved object

                // this loop will find the object of the searched container
                let findIt = _.forEach(containers, container => {
                    if (container.container === requestedContainer) {
                        containerObject = container;
                    }
                });
                containerObject = findIt[0];
                //console.log(findIt[0]);
                resolve(containerObject.container);
            }
        });
    });
}

$(function() {
    $("#lfdsubmit").click(function (e) {
        e.preventDefault();

        let lsd_modaltitle = $("#lfdmodaltitle");
        let lsd_modalcontent = $("#lfdmodalcontent");

        LFD_SearchContainer('EISU1870725')
        .then(container => { 
            ST2.db2(container); // will send the object
        })
        .catch(error => {
            console.log(error);
        });
    });
});

}

Answer №1

If the function ST2.db2(container); returns a promise, it is recommended to modify that line as follows:

return ST2.db2(container);

If it does not return a promise, you can add return null; after the function call, like this:

ST2.db2(container);
return null;

Without knowing the specifics of the ST2 definition, it is impossible to determine if the db2 method in fact returns a promise. :)

You can find further explanation about the error in the comment by the author of bluebird here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to efficiently manage multiple INSERT, SELECT, and UPDATE operations in mysql2 using nodejs

I am seeking guidance on how to approach a specific problem that I am facing. Due to my limited knowledge of databases, I am unsure of the best method to tackle this issue. The challenge I am dealing with involves receiving a 'large' amount of d ...

NodeJS: The module failed to automatically register itself

Exploring the capabilities of IBM Watson's Speech to Text API, I encountered an issue while running my NodeJS application. To handle the input audio data and utilize IBM Watson's SpeechToText package, I integrated the line-in package for streami ...

Exploring Angular testing by using mock services to simulate the behavior of other services

I am familiar with how to mock a function call to a service. However, I am facing a scenario where my MainService acts as a wrapper for multiple other services. export class MainService { constructor( public service1: Service1, public service2 ...

What is the correct way to execute a POST request?

Currently tackling a basic API project. Managed to nail the GET & DELETE requests, but the POST request is giving me a hard time. I'm almost positive it's a beginner mistake, but I can't seem to figure out the logic here. This specific file ...

Vulnerability protection against AngularJS JSON is not removed

I am currently working on an Angular app that communicates with an API. The JSON responses from the API are prefixed with )]}', as recommended in Angular's official documentation. The issue I am facing is that my browser seems to try decoding th ...

Obtaining a state hook value within an imported function in React

In order to access a value from the state hook stored in a special function, it is straightforward to do so in a functional component. For example, this can be achieved in App.js like this: import React from 'react'; import { Switch, Route, with ...

What methods can I use to insert an array of objects into a Query?

I'm currently trying to understand how I can pass an array of objects into my GraphQL query. The documentation seems a bit confusing on this matter. In my project, I am using Apollo on the frontend, Graphql-yoga on the backend, and Prisma as my databa ...

Struggling to remove an image while using the onmouseover event with a button?

I am encountering an issue with hiding an image using the onmouseover event not applied directly to it, but rather to a button element. The desired functionality is for the image to appear when the mouse hovers over and disappear when it moves away. Here&a ...

The event listener for browser.menus.onClicked is dysfunctional in Firefox

Currently, I am in the process of developing my own Firefox extension and I have encountered an issue with adding a listener to an onclick event for a context menu item. manifest.json { "manifest_version": 2, "name": "My exten ...

Feature for jotting down notes, creating a break between lines without any information present

I'm currently working on implementing a note-taking feature for my web application. However, I have encountered two issues: Firstly, I am struggling to identify line breaks within the text. While I can hardcode text with line breaks, when a user clic ...

Tips for displaying a tooltip when hovering over a label in a Material UI slider

I'm currently working on a slider quiz and my goal is to have the tooltip appear when hovering over the label on the slider. Currently, I can only see the tooltip when I hover directly on the thumb at the location of my mouse. Refer to the image belo ...

React with TypeScript: The struggle of getting LocalStorage to work

Currently, I am dealing with persistence in a todo application developed using React and TypeScript. To achieve the desired persistence, I have implemented localStorage. Allow me to share some code snippets: const [todos, setTodos] = useState<todoMod ...

The SetTimeOut function is ineffective for resetting the colour of every cell in a table

I am facing an issue with two HTML tables. The cell values in both tables are changing every 3 seconds and the background color of each cell is set based on the value from the previous cycle. Additionally, a setTimeout function is used to reset the backgro ...

Combining the total of numerous inputs that are multiplied by a specific value all at once

Hey, I've been working on a project with a table and an input field with costs using jQuery. You can check out This Fiddle for reference. $( ".total" ).change(function() { let i = 1; var input001 = document.getElementsByName(i)[0]; var ...

The results from the loop are being outputted outside of the <table> using $.each

Currently, I am making an Ajax call to fetch a large number of results from the database. I am then using jQuery to loop through these results and create a simple table. However, I am facing a problem where the loop is placing the results outside of the &l ...

Using TypeOrm QueryBuilder to establish multiple relations with a single table

Thank you for taking the time to read and offer your assistance! I am facing a specific issue with my "Offer" entity where it has multiple relations to "User". The code snippet below illustrates these relationships: @ManyToOne(() => User, (user) => ...

Retrieve the Flot graph object using Javascript

Seeking advice on a function that should return a JavaScript object. function get_temp(){ var datasets_temp = { "sens1": {data: [[1340803113,22.9],[1340803474,23],[1340803836,23],[1340804197,23.1]] }, "sens2": {data: [[134084 ...

The div element is unable to activate the modal due to tabindex issues

Seeking Assistance with a Specific Scenario I have a specific layout where a div is enclosing an image. The desired functionality is that when the div is clicked with a mouse, a small tooltip modal should appear displaying address information. This can be ...

Guide on how to smoothly navigate through an HTML page to a specific anchor point

Is there a way to use JavaScript to make the browser scroll the page to a specific anchor? In my HTML code, I have set either a name or id attribute like this: <a name="anchorName">..</a> or <h1 id="anchorName2">..&l ...

I'm having trouble saving the session, what could be the issue?

Hey there, I've created a form where users can sign up. Once the user fills in all the details and clicks submit, an Ajax request sends the form data to the database. If this process happens without any errors, a hidden div containing payment buttons ...