Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
dchertousov committed Dec 4, 2020
2 parents 144b3f3 + b6a8bb6 commit 64ca189
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uapi-json",
"version": "1.8.3",
"version": "1.8.4",
"description": "Travelport Universal API",
"main": "src/",
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/Request/RequestErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Object.assign(RequestRuntimeError, createErrorsList({
VersionParsingError: 'Error during parsing version of uapi',
UnhandledError: 'Error during request. Please try again later',
ResultsMissing: 'Missing results in response',
UAPIServiceError: 'UAPI Service responded with an error',
}, RequestRuntimeError));

// Soap errors
Expand Down
16 changes: 12 additions & 4 deletions src/Services/Air/AirParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ function airPriceRspPricingSolutionXML(obj) {
};
}

const processUAPIError = (rsp) => {
if (rsp.faultstring) {
throw new RequestRuntimeError.UAPIServiceError(rsp);
}

throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(rsp));
};

const AirErrorHandler = function (rsp) {
let errorInfo;
let code;
Expand All @@ -435,7 +443,7 @@ const AirErrorHandler = function (rsp) {
);
code = errorInfo[`common_${this.uapi_version}:Code`];
} catch (err) {
throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(rsp));
processUAPIError(rsp);
}
const pcc = utils.getErrorPcc(rsp.faultstring);
switch (code) {
Expand Down Expand Up @@ -467,7 +475,7 @@ const AirErrorHandler = function (rsp) {
case '3037': // No availability on chosen flights, unable to fare quote
throw new AirRuntimeError.NoResultsFound(rsp);
default:
throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(rsp));
processUAPIError(rsp);
}
};

Expand Down Expand Up @@ -706,7 +714,7 @@ function airGetTicketsErrorHandler(rsp) {
);
code = errorInfo[`common_${this.uapi_version}:Code`];
} catch (err) {
throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(rsp));
processUAPIError(rsp);
}
// General Air Service error
if (code === '3000') {
Expand All @@ -720,7 +728,7 @@ function airGetTicketsErrorHandler(rsp) {
pcc: utils.getErrorPcc(rsp.faultstring),
});
default:
throw new RequestRuntimeError.UnhandledError(null, new AirRuntimeError(rsp));
return processUAPIError(rsp);
}
}

Expand Down
51 changes: 51 additions & 0 deletions test/Air/AirParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ describe('#AirParser', () => {
airParser.AIR_GET_TICKETS, airParser.AIR_GET_TICKETS_ERROR_HANDLER
);
throw new Error('Skipped error!');
} catch (err) {
expect(err).to.be.an.instanceof(RequestRuntimeError.UAPIServiceError);
expect(err.data).to.deep.eq({
faultcode: 'Server.Business',
faultstring: 'Record locator not found.',
detail: {
'common_v47_0:ErrorInfo': {
'common_v47_0:Code': '3130', 'common_v47_0:Service': 'WEBSVC', 'common_v47_0:Type': 'Business', 'common_v47_0:Description': 'Record locator not found.', 'common_v47_0:TransactionId': '838261280A07425809813A4629F6C7D1', 'xmlns:common_v47_0': 'http://www.travelport.com/schema/common_v47_0'
}
}
});
}
});
it('should correctly handle errors without faultstring', async () => {
try {
airParser.AIR_GET_TICKETS_ERROR_HANDLER.uapi_version = 'v47_0';
airParser.AIR_GET_TICKETS_ERROR_HANDLER({ faultcode: 'Server.Security' });
} catch (err) {
expect(err).to.be.an.instanceof(RequestRuntimeError.UnhandledError);
}
Expand Down Expand Up @@ -866,6 +883,40 @@ describe('#AirParser', () => {
);
});

it('should handle uapi error', async () => {
const uParser = new Parser('air:AirRetrieveDocumentRsp', 'v47_0', {});
const parseFunction = airParser.AIR_ERRORS;
const xml = fs.readFileSync(`${xmlFolder}/AirGetTickets-error-general.xml`).toString();
return uParser.parse(xml)
.then(
(json) => {
const errData = uParser.mergeLeafRecursive(json['SOAP:Fault'][0]); // parse error data
return parseFunction.call(uParser, errData);
}
)
.catch((err) => {
expect(err).to.be.an.instanceof(RequestRuntimeError.UAPIServiceError);
expect(err.data).to.deep.eq({
faultcode: 'Server.Business',
faultstring: 'Record locator not found.',
detail: {
'common_v47_0:ErrorInfo': {
'common_v47_0:Code': '3130', 'common_v47_0:Service': 'WEBSVC', 'common_v47_0:Type': 'Business', 'common_v47_0:Description': 'Record locator not found.', 'common_v47_0:TransactionId': '838261280A07425809813A4629F6C7D1', 'xmlns:common_v47_0': 'http://www.travelport.com/schema/common_v47_0'
}
}
});
});
});

it('should correctly handle errors without faultstring', async () => {
try {
airParser.AIR_ERRORS.uapi_version = 'v47_0';
airParser.AIR_ERRORS({ faultcode: 'Server.Security' });
} catch (err) {
expect(err).to.be.an.instanceof(RequestRuntimeError.UnhandledError);
}
});

it('should throw AirRuntimeError.NoResultsFound error2', () => {
const uParser = new Parser('SOAP:Fault', 'v47_0', {});
const parseFunction = airParser.AIR_ERRORS.bind(uParser);
Expand Down

0 comments on commit 64ca189

Please sign in to comment.