From 5213fc0f0a6053e1ee866bb7670a2b0375889d75 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Fri, 23 Dec 2022 11:56:20 +0000 Subject: [PATCH] Use logger helper consistently, add 'no-console' ESLint rule, --- .eslintrc | 5 ++- app/index.js | 5 +-- app/lib/hydra.js | 9 ++--- app/lib/logger.js | 3 -- app/lib/osm.js | 3 +- app/manage/badges.js | 19 ++++++----- app/manage/login.js | 7 ++-- app/manage/organizations.js | 15 +++++---- app/manage/profiles.js | 15 +++++---- app/manage/teams.js | 33 ++++++++++--------- app/manage/utils.js | 3 +- app/oauth/consent.js | 3 +- migrations/20190417173534_init.js | 4 ++- migrations/20190730183820_team-locations.js | 6 ++-- .../20190805171532_team-name-required.js | 6 ++-- migrations/20190822135832_editing_policy.js | 6 ++-- .../20200130150202_team-moderator-unique.js | 6 ++-- .../20200130155125_team-member-unique.js | 6 ++-- src/components/add-member-form.js | 3 +- src/components/clients.js | 3 +- src/components/profile-attribute-form.js | 3 +- src/components/profile-form.js | 5 +-- .../[id]/badges/[badgeId]/assign/[userId].js | 7 ++-- .../[id]/badges/[badgeId]/index.js | 7 ++-- src/pages/organizations/[id]/badges/add.js | 5 +-- .../[id]/badges/assign/[userId].js | 5 +-- .../organizations/[id]/edit-privacy-policy.js | 5 +-- src/pages/organizations/[id]/edit-profiles.js | 3 +- .../organizations/[id]/edit-team-profiles.js | 3 +- src/pages/organizations/[id]/edit.js | 7 ++-- src/pages/organizations/[id]/index.js | 9 ++--- src/pages/organizations/create.js | 3 +- src/pages/teams/[id]/edit-profiles.js | 3 +- src/pages/teams/[id]/edit.js | 7 ++-- src/pages/teams/[id]/index.js | 17 +++++----- src/pages/teams/create.js | 3 +- src/pages/teams/index.js | 3 +- 37 files changed, 148 insertions(+), 107 deletions(-) delete mode 100644 app/lib/logger.js diff --git a/.eslintrc b/.eslintrc index 3cd70ec9..6cc80d80 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,5 +7,8 @@ "next/core-web-vitals", "plugin:prettier/recommended", "plugin:cypress/recommended" - ] + ], + "rules": { + "no-console": 2 + } } diff --git a/app/index.js b/app/index.js index 0ed864b6..fe82160f 100644 --- a/app/index.js +++ b/app/index.js @@ -10,6 +10,7 @@ const cors = require('cors') const manageRouter = require('./manage') const oauthRouter = require('./oauth') +const logger = require('../src/lib/logger') const dev = process.env.NODE_ENV !== 'production' const PORT = process.env.PORT || 8989 @@ -60,7 +61,7 @@ async function init() { return nextApp.render(req, res, '/uh-oh') } res.status(err.status || 500) - console.error('error', err) + logger.error('error', err) res.boom.internal('An internal error occurred.') }) @@ -71,7 +72,7 @@ async function init() { if (require.main === module) { init().then((app) => { app.listen(PORT, () => { - console.log(`Starting server on port ${PORT}`) + logger.info(`Starting server on port ${PORT}`) }) }) } diff --git a/app/lib/hydra.js b/app/lib/hydra.js index 2c8dbf32..83c4601e 100644 --- a/app/lib/hydra.js +++ b/app/lib/hydra.js @@ -10,6 +10,7 @@ const qs = require('qs') const { URL } = require('url') const { serverRuntimeConfig } = require('../../next.config') +const logger = require('../../src/lib/logger') const hydraUrl = serverRuntimeConfig.HYDRA_ADMIN_HOST var mockTlsTermination = {} @@ -29,7 +30,7 @@ function get(flow, challenge) { // This will handle any errors that aren't network related (network related errors are handled automatically) return res.json().then(function (body) { if (res.status !== 404) { - console.error('An error occurred while making a HTTP request: ', body) + logger.error('An error occurred while making a HTTP request: ', body) } return Promise.reject(new Error(body.error.message)) }) @@ -59,7 +60,7 @@ function put(flow, action, challenge, body) { // This will handle any errors that aren't network related (network related errors are handled automatically) return res.json().then(function (body) { if (res.status !== 404) { - console.error('An error occurred while making a HTTP request: ', body) + logger.error('An error occurred while making a HTTP request: ', body) } return Promise.reject(new Error(body.error.message)) }) @@ -81,7 +82,7 @@ function getClients() { // This will handle any errors that aren't network related (network related errors are handled automatically) return res.json().then(function (body) { if (res.status !== 404) { - console.error('An error occurred while making a HTTP request: ', body) + logger.error('An error occurred while making a HTTP request: ', body) } return Promise.reject(new Error(body.error.message)) }) @@ -104,7 +105,7 @@ function createClient(body) { // This will handle any errors that aren't network related (network related errors are handled automatically) return res.json().then(function (body) { if (res.status !== 404) { - console.error('An error occurred while making a HTTP request: ', body) + logger.error('An error occurred while making a HTTP request: ', body) } return Promise.reject(new Error(body.error.message)) }) diff --git a/app/lib/logger.js b/app/lib/logger.js deleted file mode 100644 index 3e88ec40..00000000 --- a/app/lib/logger.js +++ /dev/null @@ -1,3 +0,0 @@ -const pino = require('pino') - -module.exports = pino({ prettyPrint: true }) diff --git a/app/lib/osm.js b/app/lib/osm.js index 5c72583f..91488876 100644 --- a/app/lib/osm.js +++ b/app/lib/osm.js @@ -13,6 +13,7 @@ const InternalOAuthError = require('passport-oauth').InternalOAuthError const OSMStrategy = require('passport-openstreetmap').Strategy const { serverRuntimeConfig } = require('../../next.config') +const logger = require('../../src/lib/logger') // get an authentication token pair from openstreetmap function openstreetmap(req, res) { @@ -118,7 +119,7 @@ function openstreetmap(req, res) { } }) .catch((e) => { - console.error(e) + logger.error(e) return res.redirect('/') }) } else { diff --git a/app/manage/badges.js b/app/manage/badges.js index dbef3cab..e585da5e 100644 --- a/app/manage/badges.js +++ b/app/manage/badges.js @@ -5,6 +5,7 @@ const profile = require('../../src/models/profile') const { routeWrapper } = require('./utils') const team = require('../../src/models/team') const Boom = require('@hapi/boom') +const logger = require('../../src/lib/logger') /** * Get the list of badges of an organization @@ -25,7 +26,7 @@ const listBadges = routeWrapper({ .orderBy('id') reply.send(badges) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -58,7 +59,7 @@ const createBadge = routeWrapper({ .returning('*') reply.send(badge) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -119,7 +120,7 @@ const getBadge = routeWrapper({ users, }) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -151,7 +152,7 @@ const patchBadge = routeWrapper({ .returning('*') reply.send(badge) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -176,7 +177,7 @@ const deleteBadge = routeWrapper({ message: `Badge ${req.params.badgeId} deleted successfully.`, }) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -224,7 +225,7 @@ const assignUserBadge = routeWrapper({ reply.send(badge) } catch (err) { - console.log(err) + logger.error(err) if (err.code === '23505') { throw Boom.badRequest('User is already assigned to badge.') } else { @@ -250,7 +251,7 @@ const listUserBadges = routeWrapper({ const badges = await profile.getUserBadges(req.params.userId) reply.send({ badges }) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -291,7 +292,7 @@ const updateUserBadge = routeWrapper({ reply.send(badge) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -322,7 +323,7 @@ const removeUserBadge = routeWrapper({ message: `Badge ${req.params.badgeId} unassigned successfully.`, }) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, diff --git a/app/manage/login.js b/app/manage/login.js index bc8f5ed7..01161c66 100644 --- a/app/manage/login.js +++ b/app/manage/login.js @@ -1,6 +1,7 @@ const { serverRuntimeConfig } = require('../../next.config') const jwt = require('jsonwebtoken') const db = require('../../src/lib/db') +const logger = require('../../src/lib/logger') const APP_URL = process.env.APP_URL @@ -50,7 +51,7 @@ async function loginAccept(req, res) { */ if (state !== req.session.login_csrf) { req.session.destroy(function (err) { - if (err) console.error(err) + if (err) logger.error(err) return res.status(500).json('State does not match') }) } else { @@ -78,7 +79,7 @@ async function loginAccept(req, res) { req.session.idToken = result.id_token return res.redirect(`${APP_URL}/profile`) } catch (error) { - console.error(error) + logger.error(error) return res.status(500).json('Authentication failed') } } @@ -91,7 +92,7 @@ async function loginAccept(req, res) { */ function logout(req, res) { req.session.destroy(function (err) { - if (err) console.error(err) + if (err) logger.error(err) res.redirect(APP_URL) }) } diff --git a/app/manage/organizations.js b/app/manage/organizations.js index 3a6081a9..0a541818 100644 --- a/app/manage/organizations.js +++ b/app/manage/organizations.js @@ -1,5 +1,6 @@ const organization = require('../../src/models/organization') const Boom = require('@hapi/boom') +const logger = require('../../src/lib/logger') /** * List organizations that a user is a member of @@ -10,7 +11,7 @@ async function listMyOrgs(req, reply) { const orgs = await organization.listMyOrganizations(user_id) reply.send(orgs) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -28,7 +29,7 @@ async function createOrg(req, reply) { const data = await organization.create(body, user_id) reply.send(data) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -76,7 +77,7 @@ async function updateOrg(req, reply) { const data = await organization.update(id, body) reply.send(data) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -95,7 +96,7 @@ async function destroyOrg(req, reply) { await organization.destroy(id) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -118,7 +119,7 @@ async function addOwner(req, reply) { await organization.addOwner(id, Number(osmId)) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -141,7 +142,7 @@ async function removeOwner(req, reply) { await organization.removeOwner(id, Number(osmId)) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -182,7 +183,7 @@ async function removeManager(req, reply) { await organization.removeManager(id, Number(osmId)) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } diff --git a/app/manage/profiles.js b/app/manage/profiles.js index 5245f698..cd636920 100644 --- a/app/manage/profiles.js +++ b/app/manage/profiles.js @@ -4,6 +4,7 @@ const org = require('../../src/models/organization') const { pick, prop, assoc } = require('ramda') const { ValidationError, PropertyRequiredError } = require('../lib/utils') const Boom = require('@hapi/boom') +const logger = require('../../src/lib/logger') /** * Gets a user profile in an org @@ -297,7 +298,7 @@ function createProfileKeys(ownerType, profileType) { const data = await profile.addProfileKeys(attributesToAdd, ownerType, id) return reply.send(data) } catch (err) { - console.error(err) + logger.error(err) if ( err instanceof ValidationError || err instanceof PropertyRequiredError @@ -324,7 +325,7 @@ async function modifyProfileKey(req, reply) { await profile.modifyProfileKey(id, body) return reply.status(200).send() } catch (err) { - console.error(err) + logger.error(err) if ( err instanceof ValidationError || err instanceof PropertyRequiredError @@ -349,7 +350,7 @@ async function deleteProfileKey(req, reply) { await profile.deleteProfileKey(id) return reply.status(200).send() } catch (err) { - console.error(err) + logger.error(err) if ( err instanceof ValidationError || err instanceof PropertyRequiredError @@ -379,7 +380,7 @@ function getProfileKeys(ownerType, profileType) { ) return reply.send(data) } catch (err) { - console.error(err) + logger.error(err) if ( err instanceof ValidationError || err instanceof PropertyRequiredError @@ -410,7 +411,7 @@ function setProfile(profileType) { await profile.setProfile(body, profileType, id) reply.status(200).send() } catch (err) { - console.error(err) + logger.error(err) throw Boom.badImplementation() } } @@ -425,7 +426,7 @@ async function getMyProfile(req, reply) { const data = await profile.getProfile('user', user_id) return reply.send(data) } catch (err) { - console.error(err) + logger.error(err) throw Boom.badImplementation() } } @@ -437,7 +438,7 @@ async function setMyProfile(req, reply) { await profile.setProfile(body, 'user', user_id) return reply.status(200).send() } catch (err) { - console.error(err) + logger.error(err) throw Boom.badImplementation() } } diff --git a/app/manage/teams.js b/app/manage/teams.js index 03996d21..feaf16a2 100644 --- a/app/manage/teams.js +++ b/app/manage/teams.js @@ -8,6 +8,7 @@ const urlRegex = require('url-regex') const { teamsMembersModeratorsHelper } = require('./utils') const profile = require('../../src/models/profile') const Boom = require('@hapi/boom') +const logger = require('../../src/lib/logger') const isUrl = urlRegex({ exact: true }) const getOsmId = prop('osm_id') @@ -30,7 +31,7 @@ async function listTeams(req, reply) { const enhancedData = await teamsMembersModeratorsHelper(data) reply.send(enhancedData) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -52,7 +53,7 @@ async function getTeam(req, reply) { return reply.send(Object.assign({}, teamData, { org: associatedOrg })) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -81,7 +82,7 @@ const getTeamMembers = routeWrapper({ Object.assign({}, { teamId: id }, { members, moderators }) ) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -98,7 +99,7 @@ async function createTeam(req, reply) { const data = await team.create(body, user_id) reply.send(data) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -127,7 +128,7 @@ async function updateTeam(req, reply) { } reply.send(updatedTeam) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -149,7 +150,7 @@ async function assignModerator(req, reply) { const data = await team.assignModerator(teamId, osmId) reply.send(data) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -171,7 +172,7 @@ async function removeModerator(req, reply) { const data = await team.removeModerator(teamId, osmId) reply.send(data) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -187,7 +188,7 @@ async function destroyTeam(req, reply) { await team.destroy(id) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -207,7 +208,7 @@ async function addMember(req, reply) { await team.addMember(id, osmId) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -238,7 +239,7 @@ async function updateMembers(req, reply) { await team.updateMembers(id, add, remove) return reply.status(200).send() } catch (err) { - console.error(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -258,7 +259,7 @@ async function removeMember(req, reply) { await team.removeMember(id, osmId) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } @@ -280,7 +281,7 @@ const getJoinInvitations = routeWrapper({ reply.send(invitations) } catch (e) { - console.error(e) + logger.error(e) reply.boom.badRequest(e.message) } }, @@ -305,7 +306,7 @@ const createJoinInvitation = routeWrapper({ .returning('*') reply.send(invitation) } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -330,7 +331,7 @@ const deleteJoinInvitation = routeWrapper({ .del() return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -361,7 +362,7 @@ const acceptJoinInvitation = routeWrapper({ return reply.status(200).send() } } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } }, @@ -383,7 +384,7 @@ async function joinTeam(req, reply) { await team.addMember(id, osmId) return reply.status(200).send() } catch (err) { - console.log(err) + logger.error(err) throw Boom.badRequest(err.message) } } diff --git a/app/manage/utils.js b/app/manage/utils.js index af9dafb9..c037d216 100644 --- a/app/manage/utils.js +++ b/app/manage/utils.js @@ -1,5 +1,6 @@ const team = require('../../src/models/team') const { prop } = require('ramda') +const logger = require('../../src/lib/logger') const getId = prop('id') const getOsmId = prop('osm_id') @@ -48,7 +49,7 @@ function routeWrapper(config) { req.body = await validate.body.validate(req.body) } } catch (error) { - console.log(error) + logger.error(error) reply.boom.badRequest(error) } await handler(req, reply) diff --git a/app/oauth/consent.js b/app/oauth/consent.js index c42bfeb6..373bdbec 100644 --- a/app/oauth/consent.js +++ b/app/oauth/consent.js @@ -7,6 +7,7 @@ const url = require('url') const db = require('../../src/lib/db') const { serverRuntimeConfig } = require('../../next.config') const { path } = require('ramda') +const logger = require('../../src/lib/logger') async function idTokenExtraParams(sub) { const [user] = await db('users').where('id', sub) @@ -95,7 +96,7 @@ function postConsent() { }) res.redirect(accept.redirect_to) } catch (e) { - console.error(e) + logger.error(e) next(e) } } diff --git a/migrations/20190417173534_init.js b/migrations/20190417173534_init.js index fb1ef7e1..f3a24be0 100644 --- a/migrations/20190417173534_init.js +++ b/migrations/20190417173534_init.js @@ -1,3 +1,5 @@ +const logger = require('../src/lib/logger') + exports.up = async (knex) => { await knex.schema.createTable('users', (table) => { table.integer('id').primary() @@ -56,6 +58,6 @@ exports.down = async (knex) => { await knex.schema.dropTable('team') await knex.schema.dropTable('users') } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/migrations/20190730183820_team-locations.js b/migrations/20190730183820_team-locations.js index 7d7a753f..e40bb5b8 100644 --- a/migrations/20190730183820_team-locations.js +++ b/migrations/20190730183820_team-locations.js @@ -1,9 +1,11 @@ +const logger = require('../src/lib/logger') + exports.up = async function (knex) { try { await knex.raw('CREATE EXTENSION IF NOT EXISTS "postgis"') await knex.raw('ALTER TABLE team ADD COLUMN location geometry(POINT, 4326)') } catch (e) { - console.error(e) + logger.error(e) } } @@ -12,6 +14,6 @@ exports.down = async function (knex) { await knex.raw('ALTER TABLE team DROP COLUMN location') await knex.schema.raw('DROP EXTENSION "postgis" CASCADE') } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/migrations/20190805171532_team-name-required.js b/migrations/20190805171532_team-name-required.js index 2d0119a2..e9c737a7 100644 --- a/migrations/20190805171532_team-name-required.js +++ b/migrations/20190805171532_team-name-required.js @@ -1,10 +1,12 @@ +const logger = require('../src/lib/logger') + exports.up = async (knex) => { try { await knex.schema.alterTable('team', function (t) { t.string('name').notNullable().alter() }) } catch (e) { - console.error(e) + logger.error(e) } } @@ -14,6 +16,6 @@ exports.down = async (knex) => { t.string('name').nullable().alter() }) } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/migrations/20190822135832_editing_policy.js b/migrations/20190822135832_editing_policy.js index ce6587fe..539dc117 100644 --- a/migrations/20190822135832_editing_policy.js +++ b/migrations/20190822135832_editing_policy.js @@ -1,10 +1,12 @@ +const logger = require('../src/lib/logger') + exports.up = async (knex) => { try { await knex.schema.alterTable('team', function (t) { t.string('editing_policy') }) } catch (e) { - console.error(e) + logger.error(e) } } @@ -14,6 +16,6 @@ exports.down = async (knex) => { t.dropColumn('editing_policy') }) } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/migrations/20200130150202_team-moderator-unique.js b/migrations/20200130150202_team-moderator-unique.js index be14cef1..7b0c5c09 100644 --- a/migrations/20200130150202_team-moderator-unique.js +++ b/migrations/20200130150202_team-moderator-unique.js @@ -1,3 +1,5 @@ +const logger = require('../src/lib/logger') + /* Add a unique constraint on the moderator table so the same team_id and osm_id cannot be added more than once. */ @@ -13,7 +15,7 @@ exports.up = async (knex) => { table.unique(columns, keyName) ) } catch (e) { - console.error(e) + logger.error(e) } } @@ -25,6 +27,6 @@ exports.down = async (knex) => { table.dropUnique(columns, keyName) ) } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/migrations/20200130155125_team-member-unique.js b/migrations/20200130155125_team-member-unique.js index fd8f3e6f..59231b34 100644 --- a/migrations/20200130155125_team-member-unique.js +++ b/migrations/20200130155125_team-member-unique.js @@ -1,3 +1,5 @@ +const logger = require('../src/lib/logger') + /* Add a unique constraint on the member table so the same team_id and osm_id cannot be added more than once. */ @@ -13,7 +15,7 @@ exports.up = async (knex) => { table.unique(columns, keyName) ) } catch (e) { - console.error(e) + logger.error(e) } } @@ -25,6 +27,6 @@ exports.down = async (knex) => { table.dropUnique(columns, keyName) ) } catch (e) { - console.error(e) + logger.error(e) } } diff --git a/src/components/add-member-form.js b/src/components/add-member-form.js index 0ef2d3a2..98f42f9f 100644 --- a/src/components/add-member-form.js +++ b/src/components/add-member-form.js @@ -1,6 +1,7 @@ import React from 'react' import { Formik, Field, Form } from 'formik' import Button from './button' +import logger from '../lib/logger' export default function AddMemberForm({ onSubmit }) { return ( @@ -14,7 +15,7 @@ export default function AddMemberForm({ onSubmit }) { actions.setSubmitting(false) actions.resetForm({ osmId: '' }) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) actions.setStatus(e.message) } diff --git a/src/components/clients.js b/src/components/clients.js index 9694f137..35504c18 100644 --- a/src/components/clients.js +++ b/src/components/clients.js @@ -3,6 +3,7 @@ import Button from './button' import Card from './card' import theme from '../styles/theme' import join from 'url-join' +import logger from '../lib/logger' const APP_URL = process.env.APP_URL @@ -120,7 +121,7 @@ class Clients extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, clients: [], diff --git a/src/components/profile-attribute-form.js b/src/components/profile-attribute-form.js index 4a2f81d1..35c202c5 100644 --- a/src/components/profile-attribute-form.js +++ b/src/components/profile-attribute-form.js @@ -2,6 +2,7 @@ import React from 'react' import { Formik, Field, Form } from 'formik' import { assoc } from 'ramda' import Button from './button' +import logger from '../lib/logger' const validate = (values) => { const errors = {} @@ -46,7 +47,7 @@ export default function ProfileAttributeForm({ actions.setSubmitting(false) actions.resetForm(initialValues) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) actions.setStatus(e.message) } diff --git a/src/components/profile-form.js b/src/components/profile-form.js index adce80e4..3b7ebfff 100644 --- a/src/components/profile-form.js +++ b/src/components/profile-form.js @@ -15,6 +15,7 @@ import { getOrg } from '../lib/org-api' import { getTeam } from '../lib/teams-api' import Button from '../components/button' import { propOr, prop } from 'ramda' +import logger from '../lib/logger' function GenderSelectField(props) { const [field, meta, { setValue, setTouched }] = useField(props.name) @@ -141,7 +142,7 @@ export default class ProfileForm extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, loading: false, @@ -246,7 +247,7 @@ export default class ProfileForm extends Component { actions.setSubmitting(false) Router.push(returnUrl) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) actions.setStatus(e.message) } diff --git a/src/pages/organizations/[id]/badges/[badgeId]/assign/[userId].js b/src/pages/organizations/[id]/badges/[badgeId]/assign/[userId].js index 03591949..bf96ba3e 100644 --- a/src/pages/organizations/[id]/badges/[badgeId]/assign/[userId].js +++ b/src/pages/organizations/[id]/badges/[badgeId]/assign/[userId].js @@ -7,6 +7,7 @@ import { format } from 'date-fns' import { toast } from 'react-toastify' import join from 'url-join' import Router from 'next/router' +import logger from '../../../../../../lib/logger' const URL = process.env.APP_URL @@ -85,7 +86,7 @@ export default class EditBadgeAssignment extends Component { assignment, }) } catch (error) { - console.error(error) + logger.error(error) this.setState({ error, loading: false, @@ -152,7 +153,7 @@ export default class EditBadgeAssignment extends Component { toast.info('Badge updated successfully.') this.loadData() } catch (error) { - console.log(error) + logger.error(error) toast.error(`Unexpected error, please try again later.`) } }} @@ -232,7 +233,7 @@ export default class EditBadgeAssignment extends Component { toast.error( `There was an error unassigning the badge. Please try again later.` ) - console.log(error) + logger.error(error) } }} > diff --git a/src/pages/organizations/[id]/badges/[badgeId]/index.js b/src/pages/organizations/[id]/badges/[badgeId]/index.js index 49f7f28f..cedfd47b 100644 --- a/src/pages/organizations/[id]/badges/[badgeId]/index.js +++ b/src/pages/organizations/[id]/badges/[badgeId]/index.js @@ -9,6 +9,7 @@ import { toast } from 'react-toastify' import theme from '../../../../../styles/theme' import Table from '../../../../../components/tables/table' import { toDateString } from '../../../../../lib/utils' +import logger from '../../../../../lib/logger' const URL = process.env.APP_URL @@ -76,7 +77,7 @@ export default class EditBadge extends Component { assignablePeople, }) } catch (error) { - console.error(error) + logger.error(error) this.setState({ error, loading: false, @@ -170,7 +171,7 @@ export default class EditBadge extends Component { toast.error( `There was an error editing badge '${name}'. Please try again later.` ) - console.log(error) + logger.error(error) } }} render={({ isSubmitting, values, errors }) => { @@ -248,7 +249,7 @@ export default class EditBadge extends Component { toast.error( `There was an error deleting the badge. Please try again later.` ) - console.log(error) + logger.error(error) } }} > diff --git a/src/pages/organizations/[id]/badges/add.js b/src/pages/organizations/[id]/badges/add.js index 68ae7e96..37bd9e1c 100644 --- a/src/pages/organizations/[id]/badges/add.js +++ b/src/pages/organizations/[id]/badges/add.js @@ -7,6 +7,7 @@ import Button from '../../../../components/button' import Router from 'next/router' import { getRandomColor } from '../../../../lib/utils' import { toast } from 'react-toastify' +import logger from '../../../../lib/logger' const URL = process.APP_URL @@ -60,7 +61,7 @@ export default class AddBadge extends Component { org, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, org: null, @@ -101,7 +102,7 @@ export default class AddBadge extends Component { }) Router.push(join(URL, `/organizations/${orgId}`)) } catch (error) { - console.log(error) + logger.error(error) toast.error( `There was an error creating badge '${name}'. Please try again later.` ) diff --git a/src/pages/organizations/[id]/badges/assign/[userId].js b/src/pages/organizations/[id]/badges/assign/[userId].js index 89f2f78d..70065423 100644 --- a/src/pages/organizations/[id]/badges/assign/[userId].js +++ b/src/pages/organizations/[id]/badges/assign/[userId].js @@ -7,6 +7,7 @@ import { format } from 'date-fns' import { toast } from 'react-toastify' import join from 'url-join' import Router from 'next/router' +import logger from '../../../../../lib/logger' const URL = process.env.APP_URL @@ -73,7 +74,7 @@ export default class NewBadgeAssignment extends Component { badges, }) } catch (error) { - console.error(error) + logger.error(error) this.setState({ error, loading: false, @@ -136,7 +137,7 @@ export default class NewBadgeAssignment extends Component { ) ) } catch (error) { - console.log(error) + logger.error(error) if (error.message === 'User is already assigned to badge.') { toast.error( diff --git a/src/pages/organizations/[id]/edit-privacy-policy.js b/src/pages/organizations/[id]/edit-privacy-policy.js index e552251a..5452089f 100644 --- a/src/pages/organizations/[id]/edit-privacy-policy.js +++ b/src/pages/organizations/[id]/edit-privacy-policy.js @@ -4,6 +4,7 @@ import { prop } from 'ramda' import Router from 'next/router' import { getOrg, updateOrgPrivacyPolicy } from '../../../lib/org-api' import PrivacyPolicyForm from '../../../components/privacy-policy-form' +import logger from '../../../lib/logger' const APP_URL = process.env.APP_URL @@ -42,7 +43,7 @@ export default class OrgPrivacyPolicy extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, orgId: null, @@ -78,7 +79,7 @@ export default class OrgPrivacyPolicy extends Component { actions.setSubmitting(false) Router.push(join(APP_URL, `/organizations/${orgId}/edit`)) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) actions.setStatus(e.message) } diff --git a/src/pages/organizations/[id]/edit-profiles.js b/src/pages/organizations/[id]/edit-profiles.js index 9170be1f..9bab8c21 100644 --- a/src/pages/organizations/[id]/edit-profiles.js +++ b/src/pages/organizations/[id]/edit-profiles.js @@ -12,6 +12,7 @@ import { deleteAttribute, } from '../../../lib/profiles-api' import theme from '../../../styles/theme' +import logger from '../../../lib/logger' export default class OrgEditProfile extends Component { static async getInitialProps({ query }) { @@ -111,7 +112,7 @@ export default class OrgEditProfile extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, orgId: null, diff --git a/src/pages/organizations/[id]/edit-team-profiles.js b/src/pages/organizations/[id]/edit-team-profiles.js index af31789d..9c842949 100644 --- a/src/pages/organizations/[id]/edit-team-profiles.js +++ b/src/pages/organizations/[id]/edit-team-profiles.js @@ -12,6 +12,7 @@ import { deleteAttribute, } from '../../../lib/profiles-api' import theme from '../../../styles/theme' +import logger from '../../../lib/logger' export default class OrgEditTeamProfile extends Component { static async getInitialProps({ query }) { @@ -111,7 +112,7 @@ export default class OrgEditTeamProfile extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, orgId: null, diff --git a/src/pages/organizations/[id]/edit.js b/src/pages/organizations/[id]/edit.js index c458cdfd..d26296c1 100644 --- a/src/pages/organizations/[id]/edit.js +++ b/src/pages/organizations/[id]/edit.js @@ -6,6 +6,7 @@ import { getOrg, updateOrg, destroyOrg } from '../../../lib/org-api' import EditOrgForm from '../../../components/edit-org-form' import Button from '../../../components/button' import theme from '../../../styles/theme' +import logger from '../../../lib/logger' const APP_URL = process.env.APP_URL @@ -36,7 +37,7 @@ export default class OrgEdit extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, @@ -55,7 +56,7 @@ export default class OrgEdit extends Component { throw new Error('Could not delete team') } } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, }) @@ -140,7 +141,7 @@ export default class OrgEdit extends Component { actions.setSubmitting(false) Router.push(join(APP_URL, `/organizations/${org.id}`)) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) // set the form errors actions.setErrors(e) actions.setStatus(e.message) diff --git a/src/pages/organizations/[id]/index.js b/src/pages/organizations/[id]/index.js index 83f06c97..82968abe 100644 --- a/src/pages/organizations/[id]/index.js +++ b/src/pages/organizations/[id]/index.js @@ -25,6 +25,7 @@ import join from 'url-join' import { getSession } from 'next-auth/react' import TeamsTable from '../../../components/tables/teams' import UsersTable from '../../../components/tables/users' +import logger from '../../../lib/logger' const URL = process.env.APP_URL @@ -101,7 +102,7 @@ class Organization extends Component { modalIsOpen: true, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, @@ -125,7 +126,7 @@ class Organization extends Component { owners, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, managers: [], @@ -170,9 +171,9 @@ class Organization extends Component { }) } catch (e) { if (e.statusCode === 401) { - console.log("User doesn't have access to organization badges.") + logger.error("User doesn't have access to organization badges.") } else { - console.error(e) + logger.error(e) } } } diff --git a/src/pages/organizations/create.js b/src/pages/organizations/create.js index 82205a14..54ff4220 100644 --- a/src/pages/organizations/create.js +++ b/src/pages/organizations/create.js @@ -3,6 +3,7 @@ import join from 'url-join' import Router from 'next/router' import EditOrgForm from '../../components/edit-org-form' import { createOrg } from '../../lib/org-api' +import logger from '../../lib/logger' const APP_URL = process.env.APP_URL @@ -17,7 +18,7 @@ export default class OrgCreate extends Component { actions.setSubmitting(false) Router.push(join(APP_URL, `organizations/${org.id}`)) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) // set the form errors actions.setErrors(e) actions.setStatus(e.message) diff --git a/src/pages/teams/[id]/edit-profiles.js b/src/pages/teams/[id]/edit-profiles.js index b9c0a990..b7896323 100644 --- a/src/pages/teams/[id]/edit-profiles.js +++ b/src/pages/teams/[id]/edit-profiles.js @@ -12,6 +12,7 @@ import { deleteAttribute, } from '../../../lib/profiles-api' import theme from '../../../styles/theme' +import logger from '../../../lib/logger' export default class TeamEditProfile extends Component { static async getInitialProps({ query }) { @@ -111,7 +112,7 @@ export default class TeamEditProfile extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, teamId: null, diff --git a/src/pages/teams/[id]/edit.js b/src/pages/teams/[id]/edit.js index c32c16f1..54c5974d 100644 --- a/src/pages/teams/[id]/edit.js +++ b/src/pages/teams/[id]/edit.js @@ -11,6 +11,7 @@ import { getTeamAttributes, getTeamProfile, } from '../../../lib/profiles-api' +import logger from '../../../lib/logger' const APP_URL = process.env.APP_URL export default class TeamEdit extends Component { @@ -50,7 +51,7 @@ export default class TeamEdit extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, @@ -69,7 +70,7 @@ export default class TeamEdit extends Component { throw new Error('Could not delete team') } } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, }) @@ -177,7 +178,7 @@ export default class TeamEdit extends Component { actions.setSubmitting(false) Router.push(join(APP_URL, `/teams/${team.id}`)) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) // set the form errors actions.setErrors(e) actions.setStatus(e.message) diff --git a/src/pages/teams/[id]/index.js b/src/pages/teams/[id]/index.js index 88d1447d..f59ebe76 100644 --- a/src/pages/teams/[id]/index.js +++ b/src/pages/teams/[id]/index.js @@ -33,6 +33,7 @@ import { } from '../../../lib/profiles-api' import { getOrgStaff } from '../../../lib/org-api' import { toast } from 'react-toastify' +import logger from '../../../lib/logger' const APP_URL = process.env.APP_URL const Map = dynamic(() => import('../../../components/team-map'), { @@ -79,7 +80,7 @@ class Team extends Component { }) } } catch (e) { - console.error(e) + logger.error(e) toast.error(e) } } @@ -90,7 +91,7 @@ class Team extends Component { await createTeamJoinInvitation(id) this.getTeamJoinLink() } catch (e) { - console.error(e) + logger.error(e) toast.error(e) } } @@ -116,7 +117,7 @@ class Team extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, @@ -144,7 +145,7 @@ class Team extends Component { modalIsOpen: true, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, @@ -167,7 +168,7 @@ class Team extends Component { await joinTeam(id, osmId) await this.getTeam(id) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, }) @@ -190,7 +191,7 @@ class Team extends Component { await assignModerator(id, osmId) await this.getTeam() } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, loading: false, @@ -204,7 +205,7 @@ class Team extends Component { await removeModerator(id, osmId) await this.getTeam() } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, loading: false, @@ -221,7 +222,7 @@ class Team extends Component { } await this.getTeam() } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, team: null, diff --git a/src/pages/teams/create.js b/src/pages/teams/create.js index 79040ea5..0596477b 100644 --- a/src/pages/teams/create.js +++ b/src/pages/teams/create.js @@ -6,6 +6,7 @@ import { dissoc } from 'ramda' import EditTeamForm from '../../components/edit-team-form' import { getSession } from 'next-auth/react' import { getOrgStaff } from '../../models/organization' +import logger from '../../lib/logger' const APP_URL = process.env.APP_URL @@ -30,7 +31,7 @@ export default function TeamCreate({ staff }) { actions.setSubmitting(false) Router.push(join(APP_URL, `/teams/${team.id}`)) } catch (e) { - console.error(e) + logger.error(e) actions.setSubmitting(false) // set the form errors actions.setErrors(e) actions.setStatus(e.message) diff --git a/src/pages/teams/index.js b/src/pages/teams/index.js index 5ccbf167..d6563f69 100644 --- a/src/pages/teams/index.js +++ b/src/pages/teams/index.js @@ -7,6 +7,7 @@ import theme from '../../styles/theme' import join from 'url-join' import { pick, map } from 'ramda' import { getTeams } from '../../lib/teams-api' +import logger from '../../lib/logger' const Map = dynamic(import('../../components/list-map'), { ssr: false, @@ -36,7 +37,7 @@ export default class TeamList extends Component { loading: false, }) } catch (e) { - console.error(e) + logger.error(e) this.setState({ error: e, teams: [],