diff --git a/config/default.yaml b/config/default.yaml index 1668607d..aeb8855d 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -1,4 +1,4 @@ -port: 5000 +port: 8011 asyncRequestApi: { url: https://publish-api.planning.data.gov.uk, port: 8082, diff --git a/src/routes/health.js b/src/routes/health.js index fab987e2..3d1ccb76 100644 --- a/src/routes/health.js +++ b/src/routes/health.js @@ -2,6 +2,7 @@ import express from 'express' import config from '../../config/index.js' import AWS from 'aws-sdk' import { createClient } from 'redis' +import logger from '../utils/logger.js' const router = express.Router() @@ -71,7 +72,10 @@ const checkRedis = async () => { return false } }).catch((err) => { - console.log('error:', err) + logger.error(`checkRedis/connect: ${err.message}`) + if (config.environment !== 'test') { + console.error(err) + } return false }) } diff --git a/src/serverSetup/middlewares.js b/src/serverSetup/middlewares.js index f2a617a1..5286e576 100644 --- a/src/serverSetup/middlewares.js +++ b/src/serverSetup/middlewares.js @@ -6,13 +6,13 @@ import hash from '../utils/hasher.js' import config from '../../config/index.js' export function setupMiddlewares (app) { - app.use(async (req, res, next) => { + app.use((req, res, next) => { logger.info({ type: 'Request', method: req.method, endpoint: req.originalUrl, message: `${req.method} request made to ${req.originalUrl}`, - sessionId: await hash(req.sessionID) + sessionId: hash(req.sessionID) }) next() }) diff --git a/src/serverSetup/session.js b/src/serverSetup/session.js index d3b863d1..02b1e9c3 100644 --- a/src/serverSetup/session.js +++ b/src/serverSetup/session.js @@ -13,7 +13,10 @@ export function setupSession (app) { const redisClient = createClient({ url: `${urlPrefix}://${config.redis.host}:${config.redis.port}` }) - redisClient.connect().catch(logger.error) + const errorHandler = (err) => { + logger.error(`session/setupSession: redis connection error: ${err.code}`) + } + redisClient.connect().catch(errorHandler) sessionStore = new RedisStore({ client: redisClient diff --git a/src/utils/fetchLocalAuthorities.js b/src/utils/fetchLocalAuthorities.js index 5fb29790..3891ce0f 100644 --- a/src/utils/fetchLocalAuthorities.js +++ b/src/utils/fetchLocalAuthorities.js @@ -1,4 +1,6 @@ import axios from 'axios' +import logger from '../../src/utils/logger.js' +import config from '../../config/index.js' /** * Fetches a list of local authority names from a specified dataset. @@ -34,9 +36,12 @@ export const fetchLocalAuthorities = async () => { return row[1] } }).filter(name => name !== null) // Filter out null values - return names // Return the fetched data + return names } catch (error) { - console.error('Error fetching local authorities data:', error) - throw error // Rethrow the error to be handled by the caller + logger.error(`fetchLocalAuthorities: Error fetching local authorities data: ${error.message}`) + if (config.environment !== 'test') { + console.error(error) + } + throw error } } diff --git a/test/unit/health.test.js b/test/unit/health.test.js index cdee0fd7..38c59d62 100644 --- a/test/unit/health.test.js +++ b/test/unit/health.test.js @@ -52,7 +52,7 @@ describe('Health checks', () => { test('checkRedis returns false when Redis is not reachable', async () => { const mockClient = { - connect: vi.fn().mockRejectedValue(new Error()), + connect: vi.fn().mockRejectedValue(new Error('redis not reachable!')), isOpen: false, quit: vi.fn() }