Fix: [AEA-5838] - changing log levels#1955
Conversation
|
This PR is linked to a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket: AEA-5838 |
There was a problem hiding this comment.
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
errortoinfo/warn. - Refine auth middleware behavior for invalid sessions (log level changes and ensure
invalidSessionCauseis 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.
|
|
||
| mockGetUsernameFromEvent.mockReturnValue(username) | ||
| mockGetSessionIdFromEvent.mockReturnValue(sessionId) | ||
| mockGetTokenMapping.mockResolvedValue(undefined) | ||
| mockGetTokenMapping.mockRejectedValue(new Error("No matching session found")) | ||
|
|
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…to aea-5838-changing-log-levels
|



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
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