Skip to content

Fix: [AEA-5838] - changing log levels#1955

Open
jonathanwelch1-nhs wants to merge 6 commits intomainfrom
aea-5838-changing-log-levels
Open

Fix: [AEA-5838] - changing log levels#1955
jonathanwelch1-nhs wants to merge 6 commits intomainfrom
aea-5838-changing-log-levels

Conversation

@jonathanwelch1-nhs
Copy link
Contributor

https://nhsd-jira.digital.nhs.uk/browse/AEA-5838
https://nhsd-jira.digital.nhs.uk/browse/AEA-5841
https://nhsd-jira.digital.nhs.uk/browse/AEA-5837

Routine Change

Details

Changing some log levels that were showing false errors. 2 have been downgraded to warn as they are expected logs when a user is trying to make an api call without correct tokens
1 is correct behaviour so changed to info

Testing added

Copilot AI review requested due to automatic review settings March 26, 2026 12:11
@github-actions
Copy link
Contributor

This PR is linked to a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket:

AEA-5838

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts logging levels and authentication error responses to reduce false error logs during expected invalid/expired-session scenarios, and updates test expectations accordingly.

Changes:

  • Downgrade selected UI logs (e.g., “no prescriptions” and tracker user info fetch failures) from error to info/warn.
  • Refine auth middleware behavior for invalid sessions (log level changes and ensure invalidSessionCause is returned on failure paths).
  • Update unit tests to reflect the new log levels and 401 response bodies.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/cpt-ui/src/pages/PrescriptionListPage.tsx Downgrades “no prescriptions” logging from error to info.
packages/cpt-ui/src/helpers/userInfo.tsx Downgrades tracker user info fetch logging from error to warn.
packages/cpt-ui/tests/PrescriptionListPage.test.tsx Updates assertion to expect logger.info instead of logger.error.
packages/common/authFunctions/src/authenticationMiddleware.ts Adjusts invalid-session/concurrent-session branching and sets invalidSessionCause on exception paths.
packages/common/authFunctions/src/authenticationConcurrentAwareMiddleware.ts Downgrades “no matching session found” from error to warn and sets invalidSessionCause on exception paths.
packages/common/authFunctions/tests/test_authenticationMiddleware.test.ts Updates mocks/expectations for new invalid-session behavior and response body content.
packages/common/authFunctions/tests/test_authenticationConcurrentAwareMiddleware.test.ts Updates expected 401 payloads to include invalidSessionCause.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 189 to 193

mockGetUsernameFromEvent.mockReturnValue(username)
mockGetSessionIdFromEvent.mockReturnValue(sessionId)
mockGetTokenMapping.mockResolvedValue(undefined)
mockGetTokenMapping.mockRejectedValue(new Error("No matching session found"))

Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is still labeled as the token mapping being "undefined", but the updated setup now uses mockRejectedValue(...) (an error path) rather than a resolved undefined. Renaming the test (or adjusting the mock to match the label) would make the intent clearer and avoid conflating "not found" with "exception" behavior.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants