I want to show the leaderboard rank before and after the user.
file leaderboard.js:
exports.leaderboarduser = userName =>
new Promise((resolve, reject) => {
const player = user.findOne({ userName: userName });
const next_player = user
.find({ _id: { $ne: player._id }, score: { $gte: player.score } })
.sort({ score: 1, userName: 1 })
.limit(-1)[0];
const previous_player = user
.find({ _id: { $ne: player._id }, score: { $lte: player.score } })
.sort({ score: -1, userName: -1 })
.limit(-1)[0]
.then(users => {
resolve(users);
})
.catch(err =>
reject({ status: 500, message: "Internal Server Error !" })
);
});
When run:
(node:18753) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:209:11) at ServerResponse.writeHead (/root/game/node_modules/on-headers/index.js:44:26) at ServerResponse._implicitHeader (_http_server.js:200:8) at write_ (_http_outgoing.js:585:9) at ServerResponse.end (_http_outgoing.js:702:5) at ServerResponse.send (/root/game/node_modules/express/lib/response.js:221:10) at ServerResponse.json (/root/game/node_modules/express/lib/response.js:267:15) at leaderboard.leaderboarduser.then.catch.err (/root/game/routes.js:152:42) at process._tickCallback (internal/process/next_tick.js:68:7) (node:18753) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:18753) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
How can I solve this?