Better server error handling
RobTop finally got https lets goo
This commit is contained in:
parent
9d9853dec3
commit
ec4ab82eda
20 changed files with 31 additions and 27 deletions
|
@ -20,7 +20,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest(path, req.gdParams(params), function(err, resp, body) {
|
||||
|
||||
if (err || body == '-1' || !body) return res.send("-1")
|
||||
if (err) return res.send("-1")
|
||||
|
||||
comments = body.split('|')
|
||||
comments = comments.map(x => x.split(':'))
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
|
|||
|
||||
req.gdRequest('downloadGJLevel22', { levelID }, function (err, resp, body) {
|
||||
|
||||
if (err || !body || body == '-1' || body.startsWith("<")) {
|
||||
if (err) {
|
||||
if (analyze && api && req.server.downloadsDisabled) return res.send("-3")
|
||||
else if (!api && levelID < 0) return res.redirect(`/?daily=${levelID * -1}`)
|
||||
else return rejectLevel()
|
||||
|
|
|
@ -10,7 +10,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJGauntlets21', {}, function (err, resp, body) {
|
||||
|
||||
if (err || !body || body == '-1' || body.startsWith("<")) return res.send("-1")
|
||||
if (err) return res.send("-1")
|
||||
let gauntlets = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[3])
|
||||
let gauntletList = gauntlets.map(x => ({ id: +x[1], name: gauntletNames[+x[1] - 1] || "Unknown", levels: x[3].split(",") }))
|
||||
|
||||
|
|
|
@ -374,11 +374,11 @@ module.exports = async (app, req, res) => {
|
|||
// skip request by causing fake error lmao
|
||||
req.gdRequest(skipRequest ? "" : 'getGJUsers20', skipRequest ? {} : req.gdParams({ str: username, forceGD }, !forceGD), function (err1, res1, body1) {
|
||||
|
||||
let result = foundID ? foundID[0] : (accountMode || err1 || !body1 || body1 == "-1" || body1.startsWith("<")) ? username : app.parseResponse(body1)[16];
|
||||
let result = foundID ? foundID[0] : (accountMode || err1) ? username : app.parseResponse(body1)[16];
|
||||
|
||||
req.gdRequest('getGJUserInfo20', req.gdParams({ targetAccountID: result, forceGD }, !forceGD), function (err2, res2, body2) {
|
||||
|
||||
if (err2 || !body2 || body2 == '-1' || body2.startsWith("<")) return buildIcon();
|
||||
if (err2) return buildIcon();
|
||||
let iconData = app.parseResponse(body2)
|
||||
if (!foundID && !forceGD) app.userCache(req.id, iconData[16], iconData[2], iconData[1])
|
||||
return buildIcon(iconData, userCode);
|
||||
|
|
|
@ -18,7 +18,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJLevelScores211', params, function(err, resp, body) {
|
||||
|
||||
if (err || body == -1 || !body) return res.send({error: true, lastWorked: app.timeSince(req.id)})
|
||||
if (err) return res.send({error: true, lastWorked: app.timeSince(req.id)})
|
||||
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
|
||||
if (!scores.length) return res.send([])
|
||||
else app.trackSuccess(req.id)
|
||||
|
|
|
@ -16,7 +16,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJScores20', params, function(err, resp, body) {
|
||||
|
||||
if (err || body == '-1' || !body) return res.send("-1")
|
||||
if (err) return res.send("-1")
|
||||
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
|
||||
if (!scores.length) return res.send("-1")
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = async (app, req, res, api, analyze) => {
|
|||
|
||||
req.gdRequest('getGJLevels21', { str: levelID, type: 0 }, function (err, resp, body) {
|
||||
|
||||
if (err || !body || body == '-1' || body.startsWith("<") || body.startsWith("##")) return rejectLevel()
|
||||
if (err || body.startsWith("##")) return rejectLevel()
|
||||
|
||||
let preRes = body.split('#')[0].split('|', 10)
|
||||
let author = body.split('#')[1].split('|')[0].split(':')
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = async (app, req, res) => {
|
|||
function mapPackLoop() {
|
||||
req.gdRequest('getGJMapPacks21', params, function (err, resp, body) {
|
||||
|
||||
if (err || !body || body == '-1' || body.startsWith("<")) return res.send("-1")
|
||||
if (err) return res.send("-1")
|
||||
|
||||
let newPacks = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[2])
|
||||
packs = packs.concat(newPacks)
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJUserInfo20', params, function (err, resp, body) {
|
||||
|
||||
if (err || body == -1 || body == -2 || !body) return res.status(400).send(`Error counting messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (err) return res.status(400).send(`Error counting messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
else app.trackSuccess(req.id)
|
||||
let count = app.parseResponse(body)[38]
|
||||
if (!count) return res.status(400).send("Error fetching unread messages!")
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = async (app, req, res, api) => {
|
|||
|
||||
req.gdRequest('downloadGJMessage20', params, function (err, resp, body) {
|
||||
|
||||
if (err || body == -1 || !body) return res.status(400).send(`Error fetching message! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (err) return res.status(400).send(`Error fetching message! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
else app.trackSuccess(req.id)
|
||||
|
||||
let x = app.parseResponse(body)
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = async (app, req, res, api) => {
|
|||
|
||||
req.gdRequest('getGJMessages20', params, function (err, resp, body) {
|
||||
|
||||
if (err || body == -1 || body == -2 || !body) return res.status(400).send(`Error fetching messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (err) return res.status(400).send(`Error fetching messages! Messages get blocked a lot so try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
else app.trackSuccess(req.id)
|
||||
|
||||
let messages = body.split("|").map(msg => app.parseResponse(msg))
|
||||
|
|
|
@ -30,8 +30,7 @@ module.exports = async (app, req, res) => {
|
|||
params.chk = chk
|
||||
|
||||
req.gdRequest('likeGJItem211', params, function (err, resp, body) {
|
||||
if (err) return res.status(400).send("The Geometry Dash servers returned an error! Perhaps they're down for maintenance")
|
||||
if (!body || body == -1) return res.status(400).send(`The Geometry Dash servers rejected your vote! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (err) return res.status(400).send(`The Geometry Dash servers rejected your vote! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
else app.trackSuccess(req.id)
|
||||
res.status(200).send((params.like == 1 ? 'Successfully liked!' : 'Successfully disliked!') + " (this will only take effect if this is your first time doing so)")
|
||||
})
|
||||
|
|
|
@ -38,8 +38,7 @@ module.exports = async (app, req, res) => {
|
|||
params.chk = chk
|
||||
|
||||
req.gdRequest('uploadGJComment21', params, function (err, resp, body) {
|
||||
if (err) return res.status(400).send("The Geometry Dash servers returned an error! Perhaps they're down for maintenance")
|
||||
if (!body || body == -1) return res.status(400).send(`The Geometry Dash servers rejected your comment! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (err) return res.status(400).send(`The Geometry Dash servers rejected your comment! Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (body.startsWith("temp")) {
|
||||
let banStuff = body.split("_")
|
||||
return res.status(400).send(`You have been banned from commenting for ${(parseInt(banStuff[1]) / 86400).toFixed(0)} days. Reason: ${banStuff[2] || "None"}`)
|
||||
|
|
|
@ -23,9 +23,8 @@ module.exports = async (app, req, res) => {
|
|||
params.chk = chk
|
||||
|
||||
req.gdRequest('uploadGJAccComment20', params, function (err, resp, body) {
|
||||
if (err) return res.status(400).send("The Geometry Dash servers returned an error! Perhaps they're down for maintenance")
|
||||
else if (!body || body == -1) return res.status(400).send(`The Geometry Dash servers rejected your profile post! Try again later, or make sure your username and password are entered correctly. Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
if (body.startsWith("temp")) {
|
||||
if (err) return res.status(400).send(`The Geometry Dash servers rejected your profile post! Try again later, or make sure your username and password are entered correctly. Try again later, or make sure your username and password are entered correctly. Last worked: ${app.timeSince(req.id)} ago.`)
|
||||
else if (body.startsWith("temp")) {
|
||||
let banStuff = body.split("_")
|
||||
return res.status(400).send(`You have been banned from commenting for ${(parseInt(banStuff[1]) / 86400).toFixed(0)} days. Reason: ${banStuff[2] || "None"}`)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
let account = app.parseResponse(body || "")
|
||||
let dumbGDPSError = req.isGDPS && (!account[16] || account[1].toLowerCase() == "undefined")
|
||||
|
||||
if (err2 || body == '-1' || !body || dumbGDPSError) {
|
||||
if (err2 || dumbGDPSError) {
|
||||
if (!api) return res.redirect('/search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
req.gdRequest('getGJLevels21', req.gdParams(filters), function(err, resp, body) {
|
||||
|
||||
if (err || !body || body == '-1' || body.startsWith("<")) return res.send("-1")
|
||||
if (err) return res.send("-1")
|
||||
let splitBody = body.split('#')
|
||||
let preRes = splitBody[0].split('|')
|
||||
let authorList = {}
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
let songID = req.params.song
|
||||
req.gdRequest('getGJSongInfo', {songID: songID}, function(err, resp, body) {
|
||||
if (err || !body || body.startsWith("<")) return res.send('-1')
|
||||
if (err) return res.send('-1')
|
||||
else if (body < 0) return res.send(false)
|
||||
request.get('https://www.newgrounds.com/audio/listen/' + songID, function(err2, resp2, song) {
|
||||
console.log(resp2.statusCode)
|
||||
|
|
BIN
assets/gauntlets/unknown.png
Normal file
BIN
assets/gauntlets/unknown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
15
index.js
15
index.js
|
@ -105,7 +105,11 @@ app.use(async function(req, res, next) {
|
|||
let endpoint = req.endpoint
|
||||
if (params.forceGD || (params.form && params.form.forceGD)) endpoint = "http://boomlings.com/database/"
|
||||
request.post(endpoint + target + '.php', parameters, function(err, res, body) {
|
||||
return cb(err, res, body)
|
||||
let error = err
|
||||
if (!error && (err || !body || body.match(/^-\d$/) || body.startsWith("error") || body.startsWith("<"))) {
|
||||
error = {serverError: true, response: body}
|
||||
}
|
||||
return cb(error, res, body)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -150,7 +154,7 @@ try {
|
|||
app.id = secrets.id
|
||||
app.gjp = secrets.gjp || app.xor.encrypt(secrets.password)
|
||||
app.sheetsKey = secrets.sheetsKey
|
||||
if (!Number(app.id) || !secrets.password || !secrets.gjp || (secrets.password || secrets.gjp).includes("delete this line")) console.warn("Warning: No account ID and/or password has been provided in secretStuff.json! These are required for level leaderboards to work.")
|
||||
if (!Number(app.id) || (!secrets.password && !secrets.gjp) || (secrets.password || secrets.gjp).includes("delete this line")) console.warn("Warning: No account ID and/or password has been provided in secretStuff.json! These are required for level leaderboards to work.")
|
||||
if (app.sheetsKey.includes("google sheets api key")) app.sheetsKey = undefined
|
||||
}
|
||||
|
||||
|
@ -161,11 +165,11 @@ catch(e) {
|
|||
else { console.warn("There was an error parsing your secretStuff.json file!"); console.error(e) }
|
||||
}
|
||||
|
||||
app.parseResponse = function (responseBody, splitter) {
|
||||
app.parseResponse = function (responseBody, splitter=":") {
|
||||
if (!responseBody || responseBody == "-1") return {};
|
||||
if (responseBody.startsWith("\nWarning:")) responseBody = responseBody.split("\n").slice(2).join("\n").trim() // GDPS'es are wild
|
||||
if (responseBody.startsWith("<br />")) responseBody = responseBody.split("<br />").slice(2).join("<br />").trim() // Seriously screw this
|
||||
let response = responseBody.split('#')[0].split(splitter || ':');
|
||||
let response = responseBody.split('#')[0].split(splitter);
|
||||
let res = {};
|
||||
for (let i = 0; i < response.length; i += 2) {
|
||||
res[response[i]] = response[i + 1]}
|
||||
|
@ -324,4 +328,7 @@ app.use(function (err, req, res, next) {
|
|||
if (err && err.message == "Response timeout") res.status(500).send('Internal server error! (Timed out)')
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (e) => { console.log(e) });
|
||||
process.on('unhandledRejection', (e, p) => { console.log(e) });
|
||||
|
||||
app.listen(app.config.port, () => console.log(`Site online! (port ${app.config.port})`))
|
|
@ -5,7 +5,7 @@
|
|||
"license": "MIT",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"canvas": "^2.6.1",
|
||||
"canvas": "^2.8.0",
|
||||
"compression": "^1.7.4",
|
||||
"connect-timeout": "^1.9.0",
|
||||
"express": "^4.17.1",
|
||||
|
|
Loading…
Add table
Reference in a new issue