TSecret Posted October 18, 2020 Report Posted October 18, 2020 (edited) I am hosting express server with steam accounts intstances abd currently having troubles with getOffer method callback. Im not experienced enough to work with callbacks, and google answers are not really suited for my problem, so I would like to ask your help here. The code below is the functions that is executed on a get request. It calls custom function inside account instance's app.get('/tradeOffer', auth, async (req, res) => { let { offerID, username } = req.query; await accounts[username].getOffer(offerID) .then(offer => {console.log("Offer", offer)}) .catch(error => console.log(error)) res.status(200).json() }) This code is a snippet of a methods inside account's instance getOffer = async (offerID) => { console.log("Getting trade offer", offerID); this.manager.getOffer(offerID, (err, offer) => { if(err) return err; return offer; }) } The question is - how do I respond, lets say, with an offer ID on a request? Thanks in advance Edited October 18, 2020 by TSecret spelling Quote
Dr. McKay Posted October 19, 2020 Report Posted October 19, 2020 Firstly, your getOffer function is incorrect. It should look something like this: getOffer = (offerID) => { return new Promise((resolve, reject) => { console.log("Getting trade offer", offerID); this.manager.getOffer(offerID, (err, offer) => { if(err) return reject(err); resolve(offer); }); }); } I'm not super familiar with express, but I would imagine that you'd do something like this: app.get('/tradeOffer', auth, async (req, res) => { let { offerID, username } = req.query; await accounts[username].getOffer(offerID) .then(offer => {console.log("Offer", offer); res.status(200).json({id: offer.id}); }) .catch(error => console.log(error)) }) Quote
TSecret Posted October 21, 2020 Author Report Posted October 21, 2020 On 10/19/2020 at 10:16 PM, Dr. McKay said: Firstly, your getOffer function is incorrect. It should look something like this: getOffer = (offerID) => { return new Promise((resolve, reject) => { console.log("Getting trade offer", offerID); this.manager.getOffer(offerID, (err, offer) => { if(err) return reject(err); resolve(offer); }); }); } I'm not super familiar with express, but I would imagine that you'd do something like this: app.get('/tradeOffer', auth, async (req, res) => { let { offerID, username } = req.query; await accounts[username].getOffer(offerID) .then(offer => {console.log("Offer", offer); res.status(200).json({id: offer.id}); }) .catch(error => console.log(error)) }) Yep, that works. Thank you! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.