Fix TypeError when cheapest AirPricingSolution is not the first in the list#680
Draft
Fix TypeError when cheapest AirPricingSolution is not the first in the list#680
Conversation
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix airPriceRspPassengersPerReservation to select the cheapest pricing solution (matching airPriceRspPricingSolutionXML's selection logic) instead of always using priceKeys[0] - Add null-safety guard for pricingInfo being undefined - Add test fixture where cheapest solution is not the first one - Add test case verifying correct solution selection and passenger key association Co-authored-by: Smotrov <7815789+Smotrov@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix TypeError when reading air:PassengerType during passenger assignment
Fix TypeError when cheapest AirPricingSolution is not the first in the list
Mar 12, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




airPriceRspPassengersPerReservationalways read passenger type counts frompriceKeys[0](the first pricing solution), whileairPriceRspPricingSolutionXMLselected the cheapest solution. When the cheapest solution wasn't first, theAirPricingInfokeys diverged,pricingInfo.find(...)returnedundefined, and the subsequent.push()threw a TypeError.Changes
airPriceRspPassengersPerReservation— now selects the cheapest pricing solution using the sameTotalPrice.slice(3)comparison already used elsewhere, ensuring it operates on the same solution asairPriceRspPricingSolutionXML:airPriceRspPricingSolutionXML— added a null guard onpricingInfobefore calling.push()as defense-in-depth.New test fixture
AirPricingSolution.2AirPrice.cheapest-second.xml— cloned from the existing two-solution fixture with prices swapped so the second solution is cheaper.New test case — asserts that the cheapest solution's key and
TotalPriceare used, and thatBookingTravelerRefentries reference the correctAirPricingInfo.Original prompt
This section details on the original issue you should resolve
<issue_title>TypeError: Cannot read properties of undefined (reading 'air:PassengerType')</issue_title>
<issue_description>Hi, I’m encountering an error during passenger assignment when parsing AirPricingInfo.
TypeError: Cannot read properties of undefined (reading 'air:PassengerType')
at AirParser.js:384
After debugging, I found the root cause:
The code attempts to map each passenger to a corresponding AirPricingInfo using a reservationKey.
However, in some responses, the generated reservationKey does not match any AirPricingInfo.$.Key.
As a result, pricingInfo becomes undefined.
Then the code tries to execute:
pricingInfo['air:PassengerType'].push(...)
which throws the TypeError.
What I observed
reservationKey sometimes becomes undefined because the matching logic finds no suitable reservation.
pricingInfos.find(info => info.$.Key === reservationKey) then returns undefined.
Some AirPricingInfo objects also do not include the air:PassengerType field initially.
Expected behavior
The parser should safely handle missing reservationKey or missing air:PassengerType fields instead of throwing a TypeError.
Suggested fix
Before writing to pricingInfo['air:PassengerType'], add validation:
if (!pricingInfo) {
// handle missing pricingInfo gracefully
}
if (!Array.isArray(pricingInfo['air:PassengerType'])) {
pricingInfo['air:PassengerType'] = [];
}
Additional notes
This issue happens when multiple pricing solutions exist and the library selects the cheapest one, but that solution’s internal structure does not match the expected PassengerType mapping.
Please let me know if you want sample request/response XML — I can provide them.
Thanks!
XML Request:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
soap:Header/
soap:Body
<air:AirPriceReq
AuthorizedBy="user" CheckFlightDetails="false" TargetBranch="xxxxx"
TraceId="59cb0657-aa20-446e-a7bd-6c3cc7115532"
XML Response:
<air:AirPriceRsp xmlns:air="http://www.travelport.com/schema/air_v54_0" xmlns:common_v54_0="http://www.travelport.com/schema/common_v54_0" TraceId="59cb0657-aa20-446e-a7bd-6c3cc7115532" TransactionId="70A38AEC0A0E7C3140AFAC5239C0C3A2" ResponseTime="339">
<common_v54_0:ResponseMessage Code="710401" Type="Warning" ProviderCode="1G"></common_v54_0:ResponseMessage>
air:AirItinerary
<air:AirSegment Key="WAgWupxwnDKAZFccCCAAAA==" Group="0" Carrier="AV" FlightNumber="143" ProviderCode="1G" Origin="CCS" Destination="BOG" DepartureTime="2025-12-04T12:10:00.000-04:00" ArrivalTime="2025-12-04T13:15:00.000-05:00" FlightTime="125" TravelTime="125" Distance="638" ClassOfService="Q" Equipment="320" ChangeOfPlane="false" OptionalServicesIndicator="false" AvailabilitySource="S" LinkAvailability="true" PolledAvailabilityOption="O and D cache or polled status used with different local status" AvailabilityDisplayType="Fare Specific Fare Quote Unbooked">
<air:CodeshareInfo OperatingCarrier="AV">AVIANCA</air:CodeshareInfo>
<air:FlightDetails Key="WAgWu...
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.