Skip to content

Commit

Permalink
Merge pull request #117 from digital-land/rosado/minor-tweaks
Browse files Browse the repository at this point in the history
NOTICKET: minor tweaks
  • Loading branch information
GeorgeGoodall authored Jul 11, 2024
2 parents 9ceb0bc + 56e5f05 commit d652141
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
port: 5000
port: 8011
asyncRequestApi: {
url: https://publish-api.planning.data.gov.uk,
port: 8082,
Expand Down
6 changes: 5 additions & 1 deletion src/routes/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/serverSetup/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
5 changes: 4 additions & 1 deletion src/serverSetup/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/utils/fetchLocalAuthorities.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion test/unit/health.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit d652141

Please sign in to comment.