Skip to content

Commit 5213fc0

Browse files
committed
Use logger helper consistently, add 'no-console' ESLint rule,
1 parent 2dde70b commit 5213fc0

37 files changed

+148
-107
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
"next/core-web-vitals",
88
"plugin:prettier/recommended",
99
"plugin:cypress/recommended"
10-
]
10+
],
11+
"rules": {
12+
"no-console": 2
13+
}
1114
}

app/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const cors = require('cors')
1010

1111
const manageRouter = require('./manage')
1212
const oauthRouter = require('./oauth')
13+
const logger = require('../src/lib/logger')
1314

1415
const dev = process.env.NODE_ENV !== 'production'
1516
const PORT = process.env.PORT || 8989
@@ -60,7 +61,7 @@ async function init() {
6061
return nextApp.render(req, res, '/uh-oh')
6162
}
6263
res.status(err.status || 500)
63-
console.error('error', err)
64+
logger.error('error', err)
6465
res.boom.internal('An internal error occurred.')
6566
})
6667

@@ -71,7 +72,7 @@ async function init() {
7172
if (require.main === module) {
7273
init().then((app) => {
7374
app.listen(PORT, () => {
74-
console.log(`Starting server on port ${PORT}`)
75+
logger.info(`Starting server on port ${PORT}`)
7576
})
7677
})
7778
}

app/lib/hydra.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const qs = require('qs')
1010
const { URL } = require('url')
1111

1212
const { serverRuntimeConfig } = require('../../next.config')
13+
const logger = require('../../src/lib/logger')
1314
const hydraUrl = serverRuntimeConfig.HYDRA_ADMIN_HOST
1415

1516
var mockTlsTermination = {}
@@ -29,7 +30,7 @@ function get(flow, challenge) {
2930
// This will handle any errors that aren't network related (network related errors are handled automatically)
3031
return res.json().then(function (body) {
3132
if (res.status !== 404) {
32-
console.error('An error occurred while making a HTTP request: ', body)
33+
logger.error('An error occurred while making a HTTP request: ', body)
3334
}
3435
return Promise.reject(new Error(body.error.message))
3536
})
@@ -59,7 +60,7 @@ function put(flow, action, challenge, body) {
5960
// This will handle any errors that aren't network related (network related errors are handled automatically)
6061
return res.json().then(function (body) {
6162
if (res.status !== 404) {
62-
console.error('An error occurred while making a HTTP request: ', body)
63+
logger.error('An error occurred while making a HTTP request: ', body)
6364
}
6465
return Promise.reject(new Error(body.error.message))
6566
})
@@ -81,7 +82,7 @@ function getClients() {
8182
// This will handle any errors that aren't network related (network related errors are handled automatically)
8283
return res.json().then(function (body) {
8384
if (res.status !== 404) {
84-
console.error('An error occurred while making a HTTP request: ', body)
85+
logger.error('An error occurred while making a HTTP request: ', body)
8586
}
8687
return Promise.reject(new Error(body.error.message))
8788
})
@@ -104,7 +105,7 @@ function createClient(body) {
104105
// This will handle any errors that aren't network related (network related errors are handled automatically)
105106
return res.json().then(function (body) {
106107
if (res.status !== 404) {
107-
console.error('An error occurred while making a HTTP request: ', body)
108+
logger.error('An error occurred while making a HTTP request: ', body)
108109
}
109110
return Promise.reject(new Error(body.error.message))
110111
})

app/lib/logger.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/lib/osm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const InternalOAuthError = require('passport-oauth').InternalOAuthError
1313
const OSMStrategy = require('passport-openstreetmap').Strategy
1414

1515
const { serverRuntimeConfig } = require('../../next.config')
16+
const logger = require('../../src/lib/logger')
1617

1718
// get an authentication token pair from openstreetmap
1819
function openstreetmap(req, res) {
@@ -118,7 +119,7 @@ function openstreetmap(req, res) {
118119
}
119120
})
120121
.catch((e) => {
121-
console.error(e)
122+
logger.error(e)
122123
return res.redirect('/')
123124
})
124125
} else {

app/manage/badges.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const profile = require('../../src/models/profile')
55
const { routeWrapper } = require('./utils')
66
const team = require('../../src/models/team')
77
const Boom = require('@hapi/boom')
8+
const logger = require('../../src/lib/logger')
89

910
/**
1011
* Get the list of badges of an organization
@@ -25,7 +26,7 @@ const listBadges = routeWrapper({
2526
.orderBy('id')
2627
reply.send(badges)
2728
} catch (err) {
28-
console.log(err)
29+
logger.error(err)
2930
throw Boom.badRequest(err.message)
3031
}
3132
},
@@ -58,7 +59,7 @@ const createBadge = routeWrapper({
5859
.returning('*')
5960
reply.send(badge)
6061
} catch (err) {
61-
console.log(err)
62+
logger.error(err)
6263
throw Boom.badRequest(err.message)
6364
}
6465
},
@@ -119,7 +120,7 @@ const getBadge = routeWrapper({
119120
users,
120121
})
121122
} catch (err) {
122-
console.log(err)
123+
logger.error(err)
123124
throw Boom.badRequest(err.message)
124125
}
125126
},
@@ -151,7 +152,7 @@ const patchBadge = routeWrapper({
151152
.returning('*')
152153
reply.send(badge)
153154
} catch (err) {
154-
console.log(err)
155+
logger.error(err)
155156
throw Boom.badRequest(err.message)
156157
}
157158
},
@@ -176,7 +177,7 @@ const deleteBadge = routeWrapper({
176177
message: `Badge ${req.params.badgeId} deleted successfully.`,
177178
})
178179
} catch (err) {
179-
console.log(err)
180+
logger.error(err)
180181
throw Boom.badRequest(err.message)
181182
}
182183
},
@@ -224,7 +225,7 @@ const assignUserBadge = routeWrapper({
224225

225226
reply.send(badge)
226227
} catch (err) {
227-
console.log(err)
228+
logger.error(err)
228229
if (err.code === '23505') {
229230
throw Boom.badRequest('User is already assigned to badge.')
230231
} else {
@@ -250,7 +251,7 @@ const listUserBadges = routeWrapper({
250251
const badges = await profile.getUserBadges(req.params.userId)
251252
reply.send({ badges })
252253
} catch (err) {
253-
console.log(err)
254+
logger.error(err)
254255
throw Boom.badRequest(err.message)
255256
}
256257
},
@@ -291,7 +292,7 @@ const updateUserBadge = routeWrapper({
291292

292293
reply.send(badge)
293294
} catch (err) {
294-
console.log(err)
295+
logger.error(err)
295296
throw Boom.badRequest(err.message)
296297
}
297298
},
@@ -322,7 +323,7 @@ const removeUserBadge = routeWrapper({
322323
message: `Badge ${req.params.badgeId} unassigned successfully.`,
323324
})
324325
} catch (err) {
325-
console.log(err)
326+
logger.error(err)
326327
throw Boom.badRequest(err.message)
327328
}
328329
},

app/manage/login.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { serverRuntimeConfig } = require('../../next.config')
22
const jwt = require('jsonwebtoken')
33
const db = require('../../src/lib/db')
4+
const logger = require('../../src/lib/logger')
45

56
const APP_URL = process.env.APP_URL
67

@@ -50,7 +51,7 @@ async function loginAccept(req, res) {
5051
*/
5152
if (state !== req.session.login_csrf) {
5253
req.session.destroy(function (err) {
53-
if (err) console.error(err)
54+
if (err) logger.error(err)
5455
return res.status(500).json('State does not match')
5556
})
5657
} else {
@@ -78,7 +79,7 @@ async function loginAccept(req, res) {
7879
req.session.idToken = result.id_token
7980
return res.redirect(`${APP_URL}/profile`)
8081
} catch (error) {
81-
console.error(error)
82+
logger.error(error)
8283
return res.status(500).json('Authentication failed')
8384
}
8485
}
@@ -91,7 +92,7 @@ async function loginAccept(req, res) {
9192
*/
9293
function logout(req, res) {
9394
req.session.destroy(function (err) {
94-
if (err) console.error(err)
95+
if (err) logger.error(err)
9596
res.redirect(APP_URL)
9697
})
9798
}

app/manage/organizations.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const organization = require('../../src/models/organization')
22
const Boom = require('@hapi/boom')
3+
const logger = require('../../src/lib/logger')
34

45
/**
56
* List organizations that a user is a member of
@@ -10,7 +11,7 @@ async function listMyOrgs(req, reply) {
1011
const orgs = await organization.listMyOrganizations(user_id)
1112
reply.send(orgs)
1213
} catch (err) {
13-
console.log(err)
14+
logger.error(err)
1415
throw Boom.badRequest(err.message)
1516
}
1617
}
@@ -28,7 +29,7 @@ async function createOrg(req, reply) {
2829
const data = await organization.create(body, user_id)
2930
reply.send(data)
3031
} catch (err) {
31-
console.log(err)
32+
logger.error(err)
3233
throw Boom.badRequest(err.message)
3334
}
3435
}
@@ -76,7 +77,7 @@ async function updateOrg(req, reply) {
7677
const data = await organization.update(id, body)
7778
reply.send(data)
7879
} catch (err) {
79-
console.log(err)
80+
logger.error(err)
8081
throw Boom.badRequest(err.message)
8182
}
8283
}
@@ -95,7 +96,7 @@ async function destroyOrg(req, reply) {
9596
await organization.destroy(id)
9697
return reply.status(200).send()
9798
} catch (err) {
98-
console.log(err)
99+
logger.error(err)
99100
throw Boom.badRequest(err.message)
100101
}
101102
}
@@ -118,7 +119,7 @@ async function addOwner(req, reply) {
118119
await organization.addOwner(id, Number(osmId))
119120
return reply.status(200).send()
120121
} catch (err) {
121-
console.log(err)
122+
logger.error(err)
122123
throw Boom.badRequest(err.message)
123124
}
124125
}
@@ -141,7 +142,7 @@ async function removeOwner(req, reply) {
141142
await organization.removeOwner(id, Number(osmId))
142143
return reply.status(200).send()
143144
} catch (err) {
144-
console.log(err)
145+
logger.error(err)
145146
throw Boom.badRequest(err.message)
146147
}
147148
}
@@ -182,7 +183,7 @@ async function removeManager(req, reply) {
182183
await organization.removeManager(id, Number(osmId))
183184
return reply.status(200).send()
184185
} catch (err) {
185-
console.log(err)
186+
logger.error(err)
186187
throw Boom.badRequest(err.message)
187188
}
188189
}

app/manage/profiles.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const org = require('../../src/models/organization')
44
const { pick, prop, assoc } = require('ramda')
55
const { ValidationError, PropertyRequiredError } = require('../lib/utils')
66
const Boom = require('@hapi/boom')
7+
const logger = require('../../src/lib/logger')
78

89
/**
910
* Gets a user profile in an org
@@ -297,7 +298,7 @@ function createProfileKeys(ownerType, profileType) {
297298
const data = await profile.addProfileKeys(attributesToAdd, ownerType, id)
298299
return reply.send(data)
299300
} catch (err) {
300-
console.error(err)
301+
logger.error(err)
301302
if (
302303
err instanceof ValidationError ||
303304
err instanceof PropertyRequiredError
@@ -324,7 +325,7 @@ async function modifyProfileKey(req, reply) {
324325
await profile.modifyProfileKey(id, body)
325326
return reply.status(200).send()
326327
} catch (err) {
327-
console.error(err)
328+
logger.error(err)
328329
if (
329330
err instanceof ValidationError ||
330331
err instanceof PropertyRequiredError
@@ -349,7 +350,7 @@ async function deleteProfileKey(req, reply) {
349350
await profile.deleteProfileKey(id)
350351
return reply.status(200).send()
351352
} catch (err) {
352-
console.error(err)
353+
logger.error(err)
353354
if (
354355
err instanceof ValidationError ||
355356
err instanceof PropertyRequiredError
@@ -379,7 +380,7 @@ function getProfileKeys(ownerType, profileType) {
379380
)
380381
return reply.send(data)
381382
} catch (err) {
382-
console.error(err)
383+
logger.error(err)
383384
if (
384385
err instanceof ValidationError ||
385386
err instanceof PropertyRequiredError
@@ -410,7 +411,7 @@ function setProfile(profileType) {
410411
await profile.setProfile(body, profileType, id)
411412
reply.status(200).send()
412413
} catch (err) {
413-
console.error(err)
414+
logger.error(err)
414415
throw Boom.badImplementation()
415416
}
416417
}
@@ -425,7 +426,7 @@ async function getMyProfile(req, reply) {
425426
const data = await profile.getProfile('user', user_id)
426427
return reply.send(data)
427428
} catch (err) {
428-
console.error(err)
429+
logger.error(err)
429430
throw Boom.badImplementation()
430431
}
431432
}
@@ -437,7 +438,7 @@ async function setMyProfile(req, reply) {
437438
await profile.setProfile(body, 'user', user_id)
438439
return reply.status(200).send()
439440
} catch (err) {
440-
console.error(err)
441+
logger.error(err)
441442
throw Boom.badImplementation()
442443
}
443444
}

0 commit comments

Comments
 (0)