Skip to content

Commit

Permalink
fixing report to not throw errors, offenders still empty without sugg…
Browse files Browse the repository at this point in the history
…estion
  • Loading branch information
fcaps committed Nov 28, 2023
1 parent bd12dd0 commit 2217771
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions routes/views/account/post/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ let flash = {};
let request = require('request');
const {check, validationResult} = require('express-validator');

function promiseRequest(url) {
function promiseRequest(url, req) {
return new Promise(function (resolve, reject) {
request(url, function (error, res, body) {
request(url, {
headers: {
'Authorization': 'Bearer ' + req.user.data.attributes.token,
}
}, function (error, res, body) {
if (!error && res.statusCode < 300) {
resolve(body);
} else {
reject(error);
reject(error || new Error('report failed with status' + res.statusCode));
}
});
});
Expand Down Expand Up @@ -78,7 +82,7 @@ exports = module.exports = async function (req, res) {
const userFetchRoute = process.env.API_URL+'/data/player?filter='+filter+'&fields[player]=login&page[size]='+offenders.length;
let apiUsers;
try {
const userFetch = await promiseRequest(userFetchRoute);
const userFetch = await promiseRequest(userFetchRoute, req);
apiUsers = JSON.parse(userFetch);
}
catch(e){
Expand Down Expand Up @@ -126,7 +130,7 @@ exports = module.exports = async function (req, res) {
if (isGameReport){
const gameFetchRoute = process.env.API_URL+'/data/game?filter=id=='+req.body.game_id+'&fields[game]='; /* empty field here to fetch nothing but ID */
try {
const gameFetch = await promiseRequest(gameFetchRoute);
const gameFetch = await promiseRequest(gameFetchRoute, req);
const gameData = JSON.parse(gameFetch);
}
catch(e){
Expand Down
4 changes: 2 additions & 2 deletions templates/views/account/report.pug
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ block content

block js
script(type='text/javascript').
const reportable_members = '!{JSON.stringify(reportable_members)}';
const offenders_names = '!{JSON.stringify(offenders_names)}';
window.reportable_members = '!{JSON.stringify(reportable_members)}';
window.offenders_names = '!{JSON.stringify(offenders_names)}';

script(src=webpackAssetJS('report'))

0 comments on commit 2217771

Please sign in to comment.