Skip to content

Commit

Permalink
upgrade boom
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Dec 5, 2023
1 parent 7df343e commit 3684902
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/database/sthDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration.js');
const sthUtils = require(ROOT_PATH + '/lib/utils/sthUtils.js');
const sthDatabaseNaming = require(ROOT_PATH + '/lib/database/model/sthDatabaseNaming');
const mongoClient = require('mongodb').MongoClient;
const boom = require('boom');
const boom = require('@hapi/boom');
const jsoncsv = require('json-csv');
const fs = require('fs');
const path = require('path');
Expand Down
57 changes: 40 additions & 17 deletions lib/server/handlers/sthGetDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
const sthDatabase = require(ROOT_PATH + '/lib/database/sthDatabase');
const boom = require('boom');
const boom = require('@hapi/boom');
const stream = require('stream');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -70,9 +70,13 @@ function getRawData(request, reply, replyHandler) {
);
sthLogger.debug(request.sth.context, 'Responding with 500- Internal error');
const error = boom.internal(message);
error.output.payload.message = message;
//error.output.payload.message = message;
if (reply) {
response = reply.response(message);
//response = reply.response({error:error.output.peyload}).type('application/json').code(500);
response = reply
.response(error)
.type('application/json')
.code(500);
} else {
response = replyHandler(error);
}
Expand Down Expand Up @@ -125,7 +129,10 @@ function getRawData(request, reply, replyHandler) {
sthLogger.error(request.sth.context, 'Error %j when getting raw data with query %j', err, rawQuery);
sthLogger.debug(request.sth.context, 'Responding with 500 - Internal Error');
if (reply) {
response = reply.response(err);
response = reply
.response(err)
.type('application/json')
.code(500);
} else {
response = replyHandler(err);
}
Expand Down Expand Up @@ -267,9 +274,13 @@ function getAggregatedData(request, reply, replyHandler) {
);
sthLogger.debug(request.sth.context, 'Responding with 500- Internal error');
const error = boom.internal(message);
error.output.payload.message = message;
//error.output.payload.message = message;
if (reply) {
response = reply.response(error);
response = reply
.response({ error: error.output.peyload })
.type('application/json')
.code(500);
//response = reply.response(error);
} else {
response = replyHandler(error);
}
Expand Down Expand Up @@ -330,7 +341,10 @@ function getAggregatedData(request, reply, replyHandler) {
);
sthLogger.debug(request.sth.context, 'Responding with 500 - Internal Error');
if (reply) {
response = reply.response(err);
response = reply
.response(err)
.type('application/json')
.code(500);
} else {
response = replyHandler(err);
}
Expand Down Expand Up @@ -431,12 +445,16 @@ function getDataHandler(request, reply, replyHandler) {
request.method.toUpperCase() + ' ' + request.url.path + ', error=' + message
);
error = boom.badRequest(message);
error.output.payload.validation = {
source: 'query',
keys: ['lastN', 'hLimit', 'hOffset', 'filetype', 'aggrMethod', 'aggrPeriod', 'count']
};
// error.output.payload.validation = {
// source: 'query',
// keys: ['lastN', 'hLimit', 'hOffset', 'filetype', 'aggrMethod', 'aggrPeriod', 'count']
// };
if (reply) {
return reply.response(error);
return reply
.response({ error: error.output.peyload })
.type('application/json')
.code(400);
//return reply.response(error);
} else {
return replyHandler(error);
}
Expand All @@ -455,16 +473,21 @@ function getDataHandler(request, reply, replyHandler) {
request.method.toUpperCase() + ' ' + request.url.path + ', error=' + message
);
error = boom.badRequest(message);
error.output.payload.validation = {
source: 'query',
keys: ['lastN', 'hLimit', 'hOffset', 'filetype', 'aggrMethod', 'aggrPeriod', 'count']
};
// error.output.payload.validation = {
// source: 'query',
// keys: ['lastN', 'hLimit', 'hOffset', 'filetype', 'aggrMethod', 'aggrPeriod', 'count']
// };
if (reply) {
return reply.response(error);
//return reply.response(error);
return reply
.response({ error: error.output.peyload })
.type('application/json')
.code(400);

Check failure on line 485 in lib/server/handlers/sthGetDataHandler.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

Unreachable code
} else {
return replyHandler(error);
}
}
return null;
}

module.exports = getDataHandler;
2 changes: 1 addition & 1 deletion lib/server/handlers/sthGetDataHandlerV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function getDataHandler(request, reply) {
request.params.entityType = request.query.type;
request.params.version = 2;

return sthGetDataHandlerV1.getDataHandler(request, null, replyHandler);
return sthGetDataHandlerV1(request, null, replyHandler);
}

module.exports = getDataHandler;
2 changes: 1 addition & 1 deletion lib/server/handlers/sthNotificationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
const sthDatabase = require(ROOT_PATH + '/lib/database/sthDatabase');
const boom = require('boom');
const boom = require('@hapi/boom');

/**
* Returns the total number of attributes to be processed
Expand Down
2 changes: 1 addition & 1 deletion lib/server/handlers/sthRemoveDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
const sthDatabase = require(ROOT_PATH + '/lib/database/sthDatabase');
const boom = require('boom');
const boom = require('@hapi/boom');

/**
* Returns a textual description of the received request and the data included in it
Expand Down
20 changes: 10 additions & 10 deletions lib/server/sthServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ROOT_PATH = require('app-root-path');
const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
// const sthServerUtils = require(ROOT_PATH + '/lib/server/utils/sthServerUtils');
// const sthHeaderValidator = require(ROOT_PATH + '/lib/server/validators/sthHeaderValidator');
const sthHeaderValidator = require(ROOT_PATH + '/lib/server/validators/sthHeaderValidator');
const sthGetDataHandler = require(ROOT_PATH + '/lib/server/handlers/sthGetDataHandler');
const sthGetDataHandlerV2 = require(ROOT_PATH + '/lib/server/handlers/sthGetDataHandlerV2');
const sthGetVersionHandler = require(ROOT_PATH + '/lib/server/handlers/sthGetVersionHandler');
Expand Down Expand Up @@ -71,7 +71,7 @@ function doStartServer(host, port, callback) {
const options = {
validate: {
//headers: sthHeaderValidator,
query: {
query: joi.object({
// prettier-ignore
lastN: joi.number().integer().greater(-1).optional(),
// prettier-ignore
Expand All @@ -88,7 +88,7 @@ function doStartServer(host, port, callback) {
dateTo: joi.date().optional(),
filetype: joi.string().optional(),
count: joi.boolean().optional()
}
})
}
};

Expand Down Expand Up @@ -172,7 +172,7 @@ function doStartServer(host, port, callback) {
handler: sthNotificationHandler,
options: {
validate: {
//headers: sthHeaderValidator // TBD
headers: sthHeaderValidator // TBD
}
}
},
Expand All @@ -182,7 +182,7 @@ function doStartServer(host, port, callback) {
handler: sthRemoveDataHandler,
options: {
validate: {
//headers: sthHeaderValidator // TBD
headers: sthHeaderValidator // TBD
}
}
},
Expand All @@ -192,7 +192,7 @@ function doStartServer(host, port, callback) {
handler: sthRemoveDataHandler,
options: {
validate: {
//headers: sthHeaderValidator // TBD
headers: sthHeaderValidator // TBD
}
}
},
Expand All @@ -202,7 +202,7 @@ function doStartServer(host, port, callback) {
handler: sthRemoveDataHandler,
options: {
validate: {
//headers: sthHeaderValidator // TBD
headers: sthHeaderValidator // TBD
}
}
},
Expand All @@ -212,10 +212,10 @@ function doStartServer(host, port, callback) {
handler: sthSetLogLevelHandler,
options: {
validate: {
query: {
query: joi.object({
// prettier-ignore
level: joi.string().insensitive().valid('FATAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG').required()
}
})
}
}
},
Expand All @@ -226,7 +226,7 @@ function doStartServer(host, port, callback) {
},
{
method: '*',
path: '/{p*}',
path: '/{any*}',
handler: sthNotFoundHandler
}
]);
Expand Down
2 changes: 1 addition & 1 deletion lib/server/validators/sthHeaderValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const ROOT_PATH = require('app-root-path');
const sthLogger = require('logops');
const sthConfig = require(ROOT_PATH + '/lib/configuration/sthConfiguration');
const boom = require('boom');
const boom = require('@hapi/boom');

/**
* Header validation handler
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"proxyquire": "1.7.10",
"remark-cli": "~8.0.1",
"remark-preset-lint-recommended": "~4.0.1",
"request": "2.88.0",
"request": "2.88.2",
"textlint": "~11.7.6",
"textlint-filter-rule-comments": "~1.2.2",
"textlint-rule-common-misspellings": "~1.0.1",
Expand All @@ -59,10 +59,10 @@
"watch": "~1.0.2"
},
"dependencies": {
"@hapi/hapi": "17.9.0",
"@hapi/hapi": "21.3.2",
"app-root-path": "~1.2.1",
"async": "~2.0.0-rc.5",
"boom": "7.2.2",
"@hapi/boom": "10.0.1",
"bytes-counter": "~1.0.0",
"commander": "~2.9.0",
"csv-parser": "~1.9.3",
Expand Down

0 comments on commit 3684902

Please sign in to comment.