Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions server/about/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ aboutRouter.get(main, (req,res)=>{
errLogger.error( err );
res.status(500).send({error: 'a problem occured'});
}
const changeLog = JSON.parse(data);
res.json({
licence: fileContents,
version: jsonData.version,
news: changeLog[jsonData.version] || []
});
try {
const changeLog = JSON.parse(data);
res.json({
licence: fileContents,
version: jsonData.version,
news: changeLog[jsonData.version] || []
});
} catch (error) {
res.sendStatus(502);
}
});
}, undefined, (e) => {
errLogger.error( e );
Expand Down
8 changes: 7 additions & 1 deletion server/compare/lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ function compareOnId( arr1, arr2, arr1Name, arr2Name, middleware ){
}

function compareOnJSON( arr1, arr2, arr1Name, arr2Name, middleware ){
const compareValueConverter = ( item ) => JSON.stringify(item),
const compareValueConverter = ( item ) => {
try {
return JSON.stringify(item);
} catch (error) {
return;
}
},
data = compareArrays( arr1, arr2, arr1Name, arr2Name, compareValueConverter );

return middleware ? middleware(data) : data ;
Expand Down
9 changes: 6 additions & 3 deletions server/compare/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ compareRouter.get('/extensions/:extID/:ver1/:ver2', (req, res) => {
}

logger.info(params);

if( params.isValid ) res.json(compareOnId( JSON.parse(fs.readFileSync(verPath(params.version1))), JSON.parse(fs.readFileSync(verPath(params.version2))), params.version1, params.version2, sortAndRemoveDeprecated ));
else res.sendStatus(404);
try {
if( params.isValid ) res.json(compareOnId( JSON.parse(fs.readFileSync(verPath(params.version1))), JSON.parse(fs.readFileSync(verPath(params.version2))), params.version1, params.version2, sortAndRemoveDeprecated ));
else res.sendStatus(404);
} catch (error) {
res.sendStatus(404);
}
} else {
const AIPPath = ( version ) => root.resolve(`rest/AIP/versions/${version}/quality-rules.json`);
res.json(compareOnId( JSON.parse(fs.readFileSync(AIPPath(params.version1))), JSON.parse(fs.readFileSync(AIPPath(params.version2))), params.version1, params.version2, sortAndRemoveDeprecated ));
Expand Down
19 changes: 12 additions & 7 deletions server/lib/business-criteria-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ function getQualityStandardsMap ( response, sync = false, echo ){
if (err) {
console.log(err);
}
const ret = JSON.parse(data).map( e => {
return Object.assign( {}, e, {
standard: 'CAST',
icon: 'img/' + e.name.toLowerCase().replace(/\s/, '') + '.svg'
} );
});

response.json(ret);
try {
const ret = JSON.parse(data).map( e => {
return Object.assign( {}, e, {
standard: 'CAST',
icon: 'img/' + e.name.toLowerCase().replace(/\s/, '') + '.svg'
} );
});

response.json(ret);
} catch (error) {
response.sendStatus(404);
}
});
}

Expand Down
11 changes: 8 additions & 3 deletions server/lib/filterDeprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ const filterDeprecated = ( req, res, errorHandler, echo ) => {
if (err) {
return errorHandler(err, res);
}
const json = JSON.parse(data),
clean = json.filter( e => e.status !== 'deprecated');
res.send(clean);

try {
const json = JSON.parse(data),
clean = json.filter( e => e.status !== 'deprecated');
res.send(clean);
} catch (error) {
res.sendStatus(502);
}
});
};

Expand Down
10 changes: 8 additions & 2 deletions server/lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ function Glob( dirName, onFileContent, onError, onComplete ){
onError( err );
return;
}
onFileContent( fileName, JSON.parse(fileContents), index, PATH.toString() );
if ( index === len -1 && onComplete) onComplete();
try {

onFileContent( fileName, JSON.parse(fileContents), index, PATH.toString() );
if ( index === len -1 && onComplete) onComplete();
} catch (error) {
console.log(error.stack);
onComplete();
}
});
});
});
Expand Down
12 changes: 10 additions & 2 deletions server/lib/readFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ const path = require('path');
function readJsonFile( filePath, onFileContent, onComplete, onError ){
fs.readFile( path.resolve(filePath), 'utf8', ( err, fileContents ) => {
if ( err ) {
onError( err );
try {
onError( err );
} catch (error) {
console.log(error.stack);
}
return;
}
onFileContent( filePath, JSON.parse(fileContents), onComplete );
try {
onFileContent( filePath, JSON.parse(fileContents), onComplete );
} catch (error) {
console.log(error.stack);
}
});
}

Expand Down
13 changes: 9 additions & 4 deletions server/lib/ruleDetailsStruct.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ const ProcessRuleDetailsRequest = ( req, res, errorHandler ) => {

const getRulesDetailsFromFile = ( filePath ) => {
if(!fs.existsSync(filePath)) return {};
const fileData = fs.readFileSync(filePath),
data = JSON.parse(fileData);

return QualityRuleObject(data);
try {
const fileData = fs.readFileSync(filePath),
data = JSON.parse(fileData);

return QualityRuleObject(data);

} catch (error) {
console.log(error.stack);
}
};

module.exports = {
Expand Down
19 changes: 12 additions & 7 deletions server/lib/standardNotApplicable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ const Item = new Struct('id', 'name', 'href', 'count', 'notapplicable');


function isApplicable( list ){
const validationData = fs.readFileSync(path.resolve(__dirname,'validation', 'standards-validation.json'));
const v_data = JSON.parse(validationData);
return list.map( e => {
const idFound = v_data.find( a => a === e.id );

return new Item(e.id, e.name, e.href, e.count, idFound ? true : false);
});
try {
const validationData = fs.readFileSync(path.resolve(__dirname,'validation', 'standards-validation.json'));
const v_data = JSON.parse(validationData);
return list.map( e => {
const idFound = v_data.find( a => a === e.id );

return new Item(e.id, e.name, e.href, e.count, idFound ? true : false);
});

} catch (error) {
console.log(error.stack);
}
}

function handler( req, res, errorHandler ){
Expand Down
3 changes: 2 additions & 1 deletion server/lib/standards-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ function inArray( val, arr ){
}

function getQualityStandardsMap ( response, echo ){
fs.readFile(root.resolve('rest/'+ (echo ? 'Carl' :'AIP') +'/quality-standards.json'), ( err, data ) => {
fs.readFile(root.resolve('rest/'+ (echo ? 'Carl' :'AIP') +'/quality-standards.json'), ( err, data ) => {
if (err) {
console.log(err);
return response.sendStatus(404);
}
// const businessCriteria = {
// name: 'CAST',
Expand Down