Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRMP-744 PDS Error 20-A NACK #135

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/constants/enums.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {errorMessages} from "../errors/errors";

Check failure on line 1 in src/constants/enums.js

View workflow job for this annotation

GitHub Actions / eslint

Replace `errorMessages}·from·"../errors/errors"` with `·errorMessages·}·from·'../errors/errors'`

export const RecordType = {
ALL: 'ALL', // Option for querying all layers in one call
Expand Down Expand Up @@ -72,6 +72,10 @@
CODE_10: {
errorCode: '10',
errorDisplayName: 'Failed to successfully generate EHR Extract.'
},
CODE_20: {
errorCode: '20',
errorDisplayName: 'Spine system responded with an error.'
}
};

Expand Down Expand Up @@ -109,6 +113,11 @@
gp2gpError: Gp2gpError.CODE_10,
internalErrorCode: `${Gp2gpError.CODE_10.errorCode}-B`,
internalErrorDescription: errorMessages.PRESIGNED_URL_NOT_FOUND_ERROR
},
ERROR_CODE_20_A: {
gp2gpError: Gp2gpError.CODE_20,
internalErrorCode: `${Gp2gpError.CODE_20.errorCode}-A`,
internalErrorDescription: errorMessages.GET_PDS_CODE_ERROR
}
};

Expand Down
7 changes: 3 additions & 4 deletions src/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ export class ParsingError extends Error {
}
}

export class GetPdsCodeError extends Error {
constructor(error) {
super(errorMessages.GET_PDS_CODE_ERROR);
logError(errorMessages.GET_PDS_CODE_ERROR, error);
export class GetPdsCodeError extends NegativeAcknowledgementError {
constructor(error, acknowledgementErrorCode) {
super(errorMessages.GET_PDS_CODE_ERROR, acknowledgementErrorCode, error);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/services/gp2gp/__tests__/pds-retrieval-request.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import nock from 'nock';
import { getPdsOdsCode } from '../pds-retrieval-request';
import { logError, logInfo } from '../../../middleware/logging';
import { GetPdsCodeError } from '../../../errors/errors';
import { AcknowledgementErrorCode } from '../../../constants/enums';

// Mocking
jest.mock('../../../middleware/logging');
Expand Down Expand Up @@ -48,7 +50,8 @@ describe('getPdsOdsCode', () => {
it('should log and throw error when pds retrieval returns 500', async () => {
// given
let error;
const expectedError = new Error('Request failed with status code 500');
const http500Error = new Error('Request failed with status code 500');
const expectedError = new GetPdsCodeError(http500Error, AcknowledgementErrorCode.ERROR_CODE_20_A);

// when
nock(MOCK_GP2GP_MESSENGER_SERVICE_URL, HEADERS)
Expand All @@ -61,7 +64,8 @@ describe('getPdsOdsCode', () => {
}

// then
expect(error).not.toBeNull();
expect(logError).toHaveBeenCalledWith('Unable to retrieve patient from PDS', expectedError);
expect(error).toEqual(expectedError)
expect(logError).toHaveBeenCalledWith(http500Error);
expect(logError).toHaveBeenCalledWith(expect.stringContaining('internalErrorCode is: ' + expectedError.acknowledgementErrorCode.internalErrorCode));
});
});
3 changes: 2 additions & 1 deletion src/services/gp2gp/pds-retrieval-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import { config } from '../../config';
import { logInfo } from '../../middleware/logging';
import { GetPdsCodeError } from '../../errors/errors';
import { AcknowledgementErrorCode } from "../../constants/enums";

export const getPdsOdsCode = async nhsNumber => {
const { gp2gpMessengerAuthKeys, gp2gpMessengerServiceUrl } = config();
Expand All @@ -14,6 +15,6 @@ export const getPdsOdsCode = async nhsNumber => {
return response.data.data.odsCode;
})
.catch(error => {
throw new GetPdsCodeError(error);
throw new GetPdsCodeError(error, AcknowledgementErrorCode.ERROR_CODE_20_A);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the 20-A implicit?

});
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import path from 'path';
import { logError, logInfo, logWarning } from '../../../middleware/logging';
import { hasServiceStartedInTheLast5Minutes } from '../../../config';
import {
DownloadError,
DownloadError, GetPdsCodeError,
NhsNumberNotFoundError,
PatientRecordNotFoundError,
PresignedUrlNotFoundError
} from '../../../errors/errors';
import {
Expand Down Expand Up @@ -236,6 +235,12 @@ describe('continueMessageHandler', () => {
});

const testCasesForFragmentTransferErrors = [
{
errorType: GetPdsCodeError,
acknowledgementErrorCode: AcknowledgementErrorCode.ERROR_CODE_20_A,
conversationStatus: conversationStatus.OUTBOUND_FRAGMENTS_SENDING_FAILED,
failureReason: FailureReason.SENDING_FAILED
},
{
errorType: DownloadError,
acknowledgementErrorCode: AcknowledgementErrorCode.ERROR_CODE_10_A,
Expand Down
16 changes: 15 additions & 1 deletion src/services/handler/continue-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { parseConversationId } from '../parser/parsing-utilities';
import { logError, logInfo, logWarning } from '../../middleware/logging';
import { ConversationStatus, CoreStatus, FailureReason } from '../../constants/enums';
import { hasServiceStartedInTheLast5Minutes } from '../../config';
import {DownloadError, PresignedUrlNotFoundError} from "../../errors/errors";
import {DownloadError, GetPdsCodeError, PresignedUrlNotFoundError} from "../../errors/errors";
import {sendAcknowledgement} from "../gp2gp/send-acknowledgement";

export default async function continueMessageHandler(message) {
Expand Down Expand Up @@ -154,6 +154,20 @@ const handleFragmentTransferError = async (
logError('Encountered error while sending out fragments', error);

switch (true) {
case error instanceof GetPdsCodeError:
await sendAcknowledgement(
nhsNumber,
odsCode,
conversationId,
messageId,
error.acknowledgementErrorCode.gp2gpError
);
await updateConversationStatus(
conversationId,
ConversationStatus.OUTBOUND_FRAGMENTS_SENDING_FAILED,
FailureReason.SENDING_FAILED
);
break;
case error instanceof PresignedUrlNotFoundError:
await sendAcknowledgement(
nhsNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
DownloadError,
MessageIdUpdateError,
StatusUpdateError,
errorMessages, PatientRecordNotFoundError
PatientRecordNotFoundError,
GetPdsCodeError
} from '../../../errors/errors';
import {
createAndStoreOutboundMessageIds,
Expand Down Expand Up @@ -116,6 +117,12 @@ describe('transferOutEhrCore', () => {
});

const testCasesForCoreTransferErrors = [
{
errorType: GetPdsCodeError,
acknowledgementErrorCode: AcknowledgementErrorCode.ERROR_CODE_20_A,
conversationStatus: conversationStatus.OUTBOUND_FAILED,
failureReason: FailureReason.CORE_SENDING_FAILED
},
{
errorType: PatientRecordNotFoundError,
acknowledgementErrorCode: AcknowledgementErrorCode.ERROR_CODE_06_A
Expand Down
21 changes: 20 additions & 1 deletion src/services/transfer/transfer-out-ehr-core.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {PresignedUrlNotFoundError, DownloadError, PatientRecordNotFoundError} from '../../errors/errors';
import {
PresignedUrlNotFoundError,
DownloadError,
PatientRecordNotFoundError,
GetPdsCodeError
} from '../../errors/errors';
import { logError, logInfo, logWarning } from '../../middleware/logging';
import { getEhrCoreAndFragmentIdsFromRepo } from '../ehr-repo/get-ehr';
import { setCurrentSpanAttributes } from '../../config/tracing';
Expand Down Expand Up @@ -104,6 +109,20 @@ const handleCoreTransferError = async (
incomingMessageId
) => {
switch (true) {
case error instanceof GetPdsCodeError:
await sendAcknowledgement(
nhsNumber,
odsCode,
conversationId,
incomingMessageId,
error.acknowledgementErrorCode.gp2gpError
);
await updateConversationStatus(
conversationId,
ConversationStatus.OUTBOUND_FAILED,
FailureReason.CORE_SENDING_FAILED
);
break;
case error instanceof PatientRecordNotFoundError:
await sendAcknowledgement(
nhsNumber,
Expand Down
Loading