Skip to content

Commit

Permalink
Print specific message if CORE row isn't found (#99)
Browse files Browse the repository at this point in the history
* Print specific message if CORE row isn't found

* Introducing terraform-docs

* GitHub workflow fixes

* Removing terraform-docs

* Just a rename

* Secret change and documentation fixes
  • Loading branch information
chrisbloe authored Aug 13, 2024
1 parent eb8d689 commit 67ed0f4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
## When copying this to a new ORC repository...
##
## 1) Create environments for dev, test, pre-prod and prod (https://github.com/nhsconnect/<repo>/settings/environments).
## 1) Visit https://github.com/nhsconnect/<repo>/settings/environments and create environments:
## - dev
## - test
## - test-apply
## - pre-prod
## - pre-prod-apply
## - prod
## - prod-apply
##
## 2) For each environment, add the following secrets:
## - BACKEND_BUCKET
## - BACKEND_KEY
## - IAM_ROLE_READONLY
## - IAM_ROLE
## - TF_BACKEND_BUCKET
## - TF_BACKEND_DYNAMODB_TABLE
## - TF_BACKEND_KEY
##
## 3) Create the following repository secret (https://github.com/nhsconnect/<repo>/settings/secrets/actions):
## - ECR_REPOSITORY_NAME
##
## 4) Edit the ## REPOSITORY SPECIFIC ## section below.

name: Terraform Plan
name: PR Checks
on:
pull_request:
branches: [ main ]
branches:
- main

permissions:
contents: read # Required for actions/checkout
Expand All @@ -42,7 +51,7 @@ jobs:
strategy:
matrix:
environment: [dev, test, pre-prod, prod]
name: ${{ matrix.environment }}
name: Terraform Plan (${{ matrix.environment }})
runs-on: ubuntu-latest
environment: ${{ matrix.environment }}
defaults:
Expand All @@ -58,7 +67,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAM_ROLE_READONLY }}
role-to-assume: ${{ secrets.IAM_ROLE }}
aws-region: eu-west-2

- name: terraform fmt
Expand Down
8 changes: 7 additions & 1 deletion src/api/patients/patient-details-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getCurrentConversationIdForPatient,
getMessageIdsForConversation
} from '../../services/database/ehr-conversation-repository';
import { HealthRecordNotFoundError } from '../../errors/errors';
import { HealthRecordNotFoundError, CoreNotFoundError } from '../../errors/errors';

export const patientDetailsValidation = [
param('nhsNumber')
Expand Down Expand Up @@ -52,6 +52,12 @@ export const patientDetailsController = async (req, res) => {
return;
}

if (err instanceof CoreNotFoundError) {
logInfo('Did not find a core message');
res.sendStatus(503);
return;
}

logError('Could not retrieve patient health record', err);
res.sendStatus(503);
}
Expand Down
2 changes: 1 addition & 1 deletion src/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class HealthRecordNotFoundError extends Error {
}
}

export class MessageNotFoundError extends Error {
export class CoreNotFoundError extends Error {
constructor(error) {
super(errorMessages.MessageNotFound);
logError(errorMessages.MessageNotFound, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { createCore } from '../ehr-core-repository';
import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker';
import { markFragmentAsReceivedAndCreateItsParts } from '../ehr-fragment-repository';
import { HealthRecordNotFoundError, MessageNotFoundError } from '../../../errors/errors';
import { HealthRecordNotFoundError, CoreNotFoundError } from '../../../errors/errors';
import moment from 'moment-timezone';

jest.mock('../../../middleware/logging');
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('ehr-conversation-repository', () => {
// when
await expect(() => getMessageIdsForConversation(conversationId))
// then
.rejects.toThrowError(MessageNotFoundError);
.rejects.toThrowError(CoreNotFoundError);
});

it('should return health record extract message id given a conversation id for a small health record', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/database/ehr-conversation-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConversationStatus, HealthRecordStatus, RecordType } from '../../models
import { logError, logInfo } from '../../middleware/logging';
import { EhrTransferTracker } from './dynamo-ehr-transfer-tracker';
import { buildConversationUpdateParams, isInCompleteStatus } from '../../models/conversation';
import { HealthRecordNotFoundError, MessageNotFoundError } from '../../errors/errors';
import { HealthRecordNotFoundError, CoreNotFoundError } from '../../errors/errors';
import { isCore } from '../../models/core';
import { isFragment } from '../../models/fragment';
import { buildSoftDeleteUpdateParams } from '../../utilities/dynamodb-helper';
Expand Down Expand Up @@ -125,7 +125,7 @@ export const getMessageIdsForConversation = async (conversationId) => {
const fragments = items.filter(isFragment);

if (!core) {
throw new MessageNotFoundError();
throw new CoreNotFoundError();
}
const coreMessageId = core.InboundMessageId;
const fragmentMessageIds = fragments.map((message) => message.InboundMessageId);
Expand Down

0 comments on commit 67ed0f4

Please sign in to comment.