Skip to content

Commit

Permalink
Merge pull request #852 from HDRUK/features/GAT-256_replace_console_log
Browse files Browse the repository at this point in the history
removed console log and errors and sentry
  • Loading branch information
dnhdruk authored Oct 26, 2022
2 parents 6f7c2bc + 22e0330 commit 5ed22be
Show file tree
Hide file tree
Showing 62 changed files with 175 additions and 412 deletions.
2 changes: 1 addition & 1 deletion migrations/1620418612003-test_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
async function up() {
// Write migration here
//await UserModel.findOneAndUpdate({ email: 'robin.kavanagh@paconsulting.com' }, { firstname: 'robin2' });
console.log('Sample migration ran successfully');
process.stdout.write(`Sample migration ran successfully\n`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion migrations/1631268706696-shared_applications_versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function up() {
},
});
} catch (err) {
console.error(err);
process.stdout.write(`Migration error - shared applications versioning: ${err.message}\n`);
}
});

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"@google-cloud/storage": "^5.3.0",
"@hubspot/api-client": "^4.1.0",
"@sendgrid/mail": "^7.1.0",
"@sentry/node": "^6.4.1",
"@sentry/tracing": "^6.4.1",
"ajv": "^8.1.0",
"ajv-formats": "^2.0.2",
"async": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion plop-templates/repositoryPattern/controller.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class {{capitalise entityName}}Controller extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`repositoryPatter: ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
4 changes: 2 additions & 2 deletions src/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const connectToDatabase = async () => {
bufferMaxEntries: 0,
});

console.log('MongoDB connected...');
process.stdout.write(`MongoDB connected...\n`);
} catch (err) {
console.error(err.message);
process.stdout.write(`connectToDatabase : ${err.message}\n`);

process.exit(1);
}
Expand Down
29 changes: 1 addition & 28 deletions src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,11 @@ import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import { connectToDatabase } from './db';
import { initialiseAuthentication } from '../resources/auth';
import * as Sentry from '@sentry/node';
import * as Tracing from '@sentry/tracing';
import helper from '../resources/utilities/helper.util';

require('dotenv').config();

var app = express();

const readEnv = process.env.ENV || 'prod';
if (readEnv === 'test' || readEnv === 'prod') {
Sentry.init({
dsn: 'https://b6ea46f0fbe048c9974718d2c72e261b@o444579.ingest.sentry.io/5653683',
environment: helper.getEnvironment(),
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express({
// trace all requests to the default router
app,
}),
],
tracesSampleRate: 1.0,
});
// RequestHandler creates a separate execution context using domains, so that every
// transaction/span/breadcrumb is attached to its own Hub instance
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());
app.use(Sentry.Handlers.errorHandler());
}

const Account = require('./account');
const configuration = require('./configuration');

Expand Down Expand Up @@ -261,4 +234,4 @@ app.use('/api/v1/locations', require('../resources/spatialfilter/SpatialRouter')
initialiseAuthentication(app);

// launch our backend into a port
app.listen(API_PORT, () => console.log(`LISTENING ON PORT ${API_PORT}`));
app.listen(API_PORT, () => process.stdout.write(`LISTENING ON PORT ${API_PORT}\n`));
8 changes: 1 addition & 7 deletions src/controllers/datasetonboarding.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _ from 'lodash';
import axios from 'axios';
import FormData from 'form-data';
import { v4 as uuidv4 } from 'uuid';
import * as Sentry from '@sentry/node';
import { isEmpty, escapeRegExp } from 'lodash';

import { Data } from '../resources/tool/data.model';
Expand All @@ -14,8 +13,6 @@ import { PublisherModel } from '../resources/publisher/publisher.model';
import { activityLogService } from '../resources/activitylog/dependency';
const HttpClient = require('../services/httpClient/httpClient');

const readEnv = process.env.ENV || 'prod';

export default class DatasetOnboardingController {
constructor(datasetonboardingService) {
this.datasetonboardingService = datasetonboardingService;
Expand Down Expand Up @@ -614,10 +611,7 @@ export default class DatasetOnboardingController {
return res.status(400).json({ success: false, message: 'No metadata found' });
}
} catch (err) {
if (readEnv === 'test' || readEnv === 'prod') {
Sentry.captureException(err);
}
process.stdout.write(`${err.message}\n`);
process.stdout.write(`DATASETONBOARDING - Bulk upload of metadata failed : ${err.message}\n`);
return res.status(500).json({ success: false, message: 'Bulk upload of metadata failed', error: err.message });
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/resources/account/account.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ router.put('/status', passport.authenticate('jwt'), utils.checkIsInRole(ROLES.Ad

return res.json({ success: true });
} catch (err) {
console.error(err.message);
process.stdout.write(`ACCOUNT - status : ${err.message}\n`);
return res.status(500).json({ success: false, error: err });
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/resources/auth/sso/sso.discourse.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ router.get('/', function (req, res, next) {
try {
redirectUrl = discourseLogin(req.query.sso, req.query.sig, req.user);
} catch (err) {
console.error(err.message);
process.stdout.write(`Single Sign On for Discourse forum : ${err.message}\n`);
return res.status(500).send('Error authenticating the user.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/auth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const loginAndSignToken = (req, res, next) => {
try {
redirectUrl = discourseLogin(queryStringParsed.sso, queryStringParsed.sig, req.user);
} catch (err) {
console.error(err.message);
process.stdout.write(`UTILS - loginAndSignToken : ${err.message}\n`);
return res.status(500).send('Error authenticating the user.');
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/resources/bpmnworkflow/bpmnworkflow.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
businessKey: businessKey.toString(),
};
await axios.post(`${bpmnBaseUrl}/engine-rest/process-definition/key/GatewayWorkflowSimple/start`, data, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postCreateProcess : ${err.message}\n`);
});
},

Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = {
},
};
await axios.post(`${bpmnBaseUrl}/engine-rest/task/${taskId}/complete`, data, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postUpdateProcess : ${err.message}\n`);
});
},

Expand All @@ -106,7 +106,7 @@ module.exports = {
businessKey: businessKey.toString(),
};
await axios.post(`${bpmnBaseUrl}/engine-rest/process-definition/key/GatewayReviewWorkflowComplex/start`, data, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postStartPreReview : ${err.message}\n`);
});
},

Expand Down Expand Up @@ -134,31 +134,31 @@ module.exports = {
},
};
await axios.post(`${bpmnBaseUrl}/engine-rest/task/${taskId}/complete`, data, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postStartManagerReview : ${err.message}\n`);
});
},

postManagerApproval: async bpmContext => {
// Manager has approved sectoin
let { businessKey } = bpmContext;
await axios.post(`${bpmnBaseUrl}/api/gateway/workflow/v1/manager/completed/${businessKey}`, bpmContext.config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postManagerApproval : ${err.message}\n`);
});
},

postStartStepReview: async bpmContext => {
//Start Step-Review process
let { businessKey } = bpmContext;
await axios.post(`${bpmnBaseUrl}/api/gateway/workflow/v1/complete/review/${businessKey}`, bpmContext, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postStartStepReview : ${err.message}\n`);
});
},

postCompleteReview: async bpmContext => {
//Start Next-Step process
let { businessKey } = bpmContext;
await axios.post(`${bpmnBaseUrl}/api/gateway/workflow/v1/reviewer/complete/${businessKey}`, bpmContext, config).catch(err => {
console.error(err.message);
process.stdout.write(`BPMN - postCompleteReview : ${err.message}\n`);
});
},
};
2 changes: 1 addition & 1 deletion src/resources/cohort/cohort.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class CohortController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`COHORT - getCohort : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
6 changes: 3 additions & 3 deletions src/resources/cohortprofiling/cohortprofiling.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class CohortProfilingController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`COHORT - getCohortProfilingByVariable : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand All @@ -52,7 +52,7 @@ export default class CohortProfilingController extends Controller {
// 2. Return Cohort Profiling data
return res.status(200).json({ success: true, cohortProfiling });
} catch (err) {
console.error(err.message);
process.stdout.write(`COHORT - getCohortProfiling : ${err.message}\n`);
return res.status(500).json({ success: false, message: err.message });
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class CohortProfilingController extends Controller {
// Return Cohort Profiling data
return res.status(200).json({ success: true, cohortProfiling });
} catch (err) {
console.error(err.message);
process.stdout.write(`COHORT - saveCohortProfiling : ${err.message}\n`);
return res.status(500).json({ success: false, message: err.message });
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/resources/course/course.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ const setStatus = async req => {

resolve(id);
} catch (err) {
console.error(err.message);
process.stdout.write(`COURSE - setStatus : ${err.message}\n`);
reject(new Error(err));
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/resources/course/v2/course.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class CourseController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`COURSE - setStatus : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand All @@ -52,7 +52,7 @@ export default class CourseController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`COURSE - getCourses : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class DataUseRegisterController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`DATA USE REGISTER - getDataUseRegister : ${err.message}`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
4 changes: 2 additions & 2 deletions src/resources/datarequest/amendment/amendment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class AmendmentController extends Controller {
// 9. Save changes to database
await accessRecord.save(async err => {
if (err) {
console.error(err.message);
process.stdout.write(`AMENDMENT - setAmendment : ${err.message}\n`);
return res.status(500).json({ status: 'error', message: err.message });
} else {
// 10. Update json schema and question answers with modifications since original submission and retain previous version requested updates
Expand Down Expand Up @@ -247,7 +247,7 @@ export default class AmendmentController extends Controller {
// 9. Save changes to database
await accessRecord.save(async err => {
if (err) {
console.error(err.message);
process.stdout.write(`AMENDMENT - requestAmendments : ${err.message}\n`);
return res.status(500).json({ status: 'error', message: err.message });
} else {
// 10. Send update request notifications
Expand Down
2 changes: 1 addition & 1 deletion src/resources/datarequest/datarequest.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ export default class DataRequestController extends Controller {
// 8. Return successful response
return res.status(200).json({ status: 'success' });
} catch (err) {
console.error(err.message);
process.stdout.write(`DATA REQUEST - updateAccessRequestDeleteFile : ${err.message}\n`);
res.status(500).json({ status: 'error', message: err.message });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class DatarequestschemaController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`DATA REQUEST - getDatarequestschema : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ async function archiveOtherVersions(id, dataSetId, status) {
);
}
} catch (err) {
console.error(err.message);
process.stdout.write(`DATA REQUEST - archiveOtherVersions : ${err.message}\n`);
}
}
2 changes: 1 addition & 1 deletion src/resources/datarequest/utils/datarequest.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const getUserPermissionsForApplication = (application, userId, _id) => {
}
return { authorised, userType };
} catch (err) {
console.error(err.message);
process.stdout.write(`DATA REQUEST - getUserPermissionsForApplication : ${err.message}\n`);
return { authorised: false, userType: '' };
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/resources/dataset/dataset.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class DatasetController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`DATA SET - getDataset : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand All @@ -48,7 +48,7 @@ export default class DatasetController extends Controller {
});
} catch (err) {
// Return error response if something goes wrong
console.error(err.message);
process.stdout.write(`DATA SET - getDatasets : ${err.message}\n`);
return res.status(500).json({
success: false,
message: 'A server error occurred, please try again',
Expand Down
13 changes: 2 additions & 11 deletions src/resources/dataset/v1/dataset.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import escape from 'escape-html';
import { Course } from '../../course/course.model';
import { DataUseRegister } from '../../dataUseRegister/dataUseRegister.model';
import { filtersService } from '../../filters/dependency';
import * as Sentry from '@sentry/node';
const router = express.Router();
const rateLimit = require('express-rate-limit');

Expand All @@ -17,8 +16,6 @@ const datasetLimiter = rateLimit({
message: 'Too many calls have been made to this api from this IP, please try again after an hour',
});

const readEnv = process.env.ENV || 'prod';

router.post('/', async (req, res) => {
try {
// Check to see if header is in json format
Expand Down Expand Up @@ -46,10 +43,7 @@ router.post('/', async (req, res) => {
// Return response indicating job has started (do not await async import)
return res.status(200).json({ success: true, message: 'Caching started' });
} catch (err) {
if (readEnv === 'test' || readEnv === 'prod') {
Sentry.captureException(err);
}
console.error(err.message);
process.stdout.write(`DATASET - Caching failed : ${err.message}\n`);
return res.status(500).json({ success: false, message: 'Caching failed' });
}
});
Expand Down Expand Up @@ -78,10 +72,7 @@ router.post('/updateServices', async (req, res) => {

return res.status(200).json({ success: true, message: 'Services Update started' });
} catch (err) {
if (readEnv === 'test' || readEnv === 'prod') {
Sentry.captureException(err);
}
console.error(err.message);
process.stdout.write(`DATASET - Services update failed : ${err.message}\n`);
return res.status(500).json({ success: false, message: 'Services update failed' });
}
});
Expand Down
Loading

0 comments on commit 5ed22be

Please sign in to comment.