From 3883c0904e1b23325bdc26b5980897779e7f6b0f Mon Sep 17 00:00:00 2001 From: Dmitry Chertousov Date: Tue, 22 Mar 2022 19:31:56 +0100 Subject: [PATCH 1/3] TC-2970 / More typed errors throw and better handling --- src/Services/Air/AirErrors.js | 2 ++ src/Services/Air/AirParser.js | 26 +++++++++++++++----------- test/Air/AirParser.test.js | 18 +++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Services/Air/AirErrors.js b/src/Services/Air/AirErrors.js index adcc22e4..9b57bf4f 100644 --- a/src/Services/Air/AirErrors.js +++ b/src/Services/Air/AirErrors.js @@ -112,6 +112,8 @@ Object.assign(AirRuntimeError, createErrorsList({ NoValidFare: 'No valid fare for input criteria.', TravelersListError: 'Not all BookingTravelers present in list or wrong lookup keys provided', ParseTicketPNRError: ['Failed to parse PNR from ticket information', errorCodes.Validation], + HostErrorDuringTicketRetrieve: 'Host error during ticket retrieve', + AccessedByAnotherTransaction: 'Accessed by another transaction. Retry later', UnableToRetrieveTickets: ['Unable to retrieve tickets list', errorCodes.NotFound], TicketInfoIncomplete: 'Ticket information is incomplete', RequestInconsistency: 'Request faced race condition. Please retry again', diff --git a/src/Services/Air/AirParser.js b/src/Services/Air/AirParser.js index c6404f35..ac5f6249 100644 --- a/src/Services/Air/AirParser.js +++ b/src/Services/Air/AirParser.js @@ -16,6 +16,7 @@ const fareCalculationPattern = /^([\s\S]+)END($|\s)/; const firstOriginPattern = /^(?:s-)?(?:\d{2}[a-z]{3}\d{2}\s+)?([a-z]{3})/i; const noAgreementPattern = /NO AGENCY AGREEMENT/i; const unableToRetreivePattern = /UNABLE TO RETRIEVE/i; +const ticketRetrieveError = /HOST ERROR DURING TICKET RETRIEVE/i; const parseFareCalculation = (str) => { const fareCalculation = str.match(fareCalculationPattern)[1]; @@ -464,19 +465,22 @@ function processUAPIError(source) { throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(source)); } - if (noAgreementPattern.test(uapiErrorMessage)) { - const pcc = utils.getErrorPcc(uapiErrorMessage); - throw new AirRuntimeError.NoAgreement({ pcc }); - } + const pcc = utils.getErrorPcc(uapiErrorMessage); - if (unableToRetreivePattern.test(uapiErrorMessage)) { - throw new AirRuntimeError.UnableToRetrieve(source); + switch (true) { + case noAgreementPattern.test(uapiErrorMessage): + utils.getErrorPcc(uapiErrorMessage); + throw new AirRuntimeError.NoAgreement({ pcc }); + case unableToRetreivePattern.test(uapiErrorMessage): + throw new AirRuntimeError.UnableToRetrieve(source); + case ticketRetrieveError.test(uapiErrorMessage): + throw new AirRuntimeError.UnableToRetrieve(source); + default: + throw new RequestRuntimeError.UAPIServiceError({ + ...source, + faultstring: uapiErrorMessage.toUpperCase() + }); } - - throw new RequestRuntimeError.UAPIServiceError({ - ...source, - faultstring: uapiErrorMessage.toUpperCase() - }); } const AirErrorHandler = function (rsp) { diff --git a/test/Air/AirParser.test.js b/test/Air/AirParser.test.js index 600cc5a6..2a259174 100644 --- a/test/Air/AirParser.test.js +++ b/test/Air/AirParser.test.js @@ -568,17 +568,17 @@ describe('#AirParser', () => { }); }); - it('should return error when not available to return ticket', (done) => { + it('should return error when not available to return ticket', async () => { const uParser = new Parser('air:AirRetrieveDocumentRsp', 'v47_0', {}); const parseFunction = airParser.AIR_GET_TICKET; - const xml = fs.readFileSync(`${xmlFolder}/getTicket_FAILED.xml`).toString(); - uParser.parse(xml) - .then(json => parseFunction.call(uParser, json)) - .then(() => done(new Error('Error has not occurred'))) - .catch((err) => { - expect(err).to.be.an.instanceof(RequestRuntimeError.UAPIServiceError); - done(); - }); + try { + const xml = fs.readFileSync(`${xmlFolder}/getTicket_FAILED.xml`).toString(); + const json = await uParser.parse(xml); + parseFunction.call(uParser, json); + throw new Error('Error has not occurred'); + } catch (err) { + expect(err).to.be.an.instanceof(AirRuntimeError.UnableToRetrieve); + } }); it('should parse imported ticket', () => { From f72dee16f964d959289199ea6d476251ad528805 Mon Sep 17 00:00:00 2001 From: Dmitry Chertousov Date: Tue, 22 Mar 2022 19:32:19 +0100 Subject: [PATCH 2/3] TC-2970 / Versions up --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7695a560..e0b69559 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uapi-json", - "version": "1.12.2", + "version": "1.12.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 961f1881..5b0ed761 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uapi-json", - "version": "1.12.2", + "version": "1.12.3", "description": "Travelport Universal API", "main": "src/", "files": [ From fc544f728ed1d84de7e84dea9dd18382c211073f Mon Sep 17 00:00:00 2001 From: Dmitry Chertousov Date: Tue, 22 Mar 2022 20:12:01 +0100 Subject: [PATCH 3/3] TC-2970 / Another error handler added --- src/Services/Air/AirParser.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Services/Air/AirParser.js b/src/Services/Air/AirParser.js index ac5f6249..7280c25a 100644 --- a/src/Services/Air/AirParser.js +++ b/src/Services/Air/AirParser.js @@ -16,7 +16,8 @@ const fareCalculationPattern = /^([\s\S]+)END($|\s)/; const firstOriginPattern = /^(?:s-)?(?:\d{2}[a-z]{3}\d{2}\s+)?([a-z]{3})/i; const noAgreementPattern = /NO AGENCY AGREEMENT/i; const unableToRetreivePattern = /UNABLE TO RETRIEVE/i; -const ticketRetrieveError = /HOST ERROR DURING TICKET RETRIEVE/i; +const ticketRetrieveErrorPattern = /HOST ERROR DURING TICKET RETRIEVE/i; +const accessedByAnotherTransactionPattern = /ACCESSED BY ANOTHER TRANSACTION/i; const parseFareCalculation = (str) => { const fareCalculation = str.match(fareCalculationPattern)[1]; @@ -473,8 +474,10 @@ function processUAPIError(source) { throw new AirRuntimeError.NoAgreement({ pcc }); case unableToRetreivePattern.test(uapiErrorMessage): throw new AirRuntimeError.UnableToRetrieve(source); - case ticketRetrieveError.test(uapiErrorMessage): + case ticketRetrieveErrorPattern.test(uapiErrorMessage): throw new AirRuntimeError.UnableToRetrieve(source); + case accessedByAnotherTransactionPattern.test(uapiErrorMessage): + throw new AirRuntimeError.AccessedByAnotherTransaction(source); default: throw new RequestRuntimeError.UAPIServiceError({ ...source,