xDimGG / node-steamapi

An object-oriented Steam API wrapper for Node.js developers.
https://www.npmjs.com/package/steamapi
177 stars 43 forks source link

Network errors crash node.js and cannot be caught #32

Closed patkub closed 1 year ago

patkub commented 2 years ago

Sometimes when using node-steamapi, a network error will crash the entire node.js process:

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND api.steampowered.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (_http_client.js:432:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:84:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'api.steampowered.com'
}

We have the following Express route which uses node-steamapi. It takes a valid steam id as a query parameter, calls steam.resolve, then uses steam.getUserSummary and replies back with json containing the summary. Wrapping the code in a try...catch block doesn't help. Example request: http://localhost:3000/summary?id=76561197989862681

router.get('/summary', function(req, res) {
    // get steam id as query parameters
    const pId = steam.resolve(req.query.id)
    pId.then((id) => {
        // get user summary
        const pSummary = steam.getUserSummary(id)
        pSummary.then((summary) => {
            // return summary data
            return res.status(200).json({
                status: "success",
                data: summary,
            })
        })
        .catch((reason) => {
            // error getting user summary
            return res.status(404).json({
                status: "error",
                message: reason.message,
            })
        })
    })
    .catch((reason) => {
        // error getting user summary
        return res.status(404).json({
            status: "error",
            message: reason.message,
        })
    })
});

cc: @ww2497 @ZacharyCChang0828 @mss6522

milobluebell commented 1 year ago

the same

xDimGG commented 1 year ago

I've changed to using node-fetch now so this should be fixed. Closing the issue for now.