Commit 3ada89ae authored by Volker Krause's avatar Volker Krause
Browse files

Properly handle empty ÖBB vehicle layout responses

parent 040cceb5
Pipeline #50938 canceled with stage
{"trainName":"XX 999","hasWifi":false,"scheduledDeparture":null,"actualDeparture":null,"scheduledArrival":null,"actualArrival":null,"trainStation":{"name":"","evaCode":"9900261"},"platform":null,"wagons":[]}
......@@ -94,6 +94,12 @@ private Q_SLOTS:
QVERIFY(!departureJson.isEmpty());
QCOMPARE(departureJson, departureRef);
}
void testInvalid()
{
KPublicTransport::OebbVehicleLayoutParser parser;
QVERIFY(!parser.parse(readFile(QLatin1String(SOURCE_DIR "/data/oebb/invalid-input.json"))));
}
};
QTEST_GUILESS_MAIN(OebbParserTest)
......
......@@ -47,7 +47,8 @@ bool OebbBackend::queryVehicleLayout(const VehicleLayoutRequest &request, Vehicl
Cache::addVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey(), {p.vehicle, p.platform, p.departure}, {}, std::chrono::minutes(2));
addResult(reply, p.vehicle, p.platform, p.departure);
} else {
addError(reply, Reply::UnknownError, {});
Cache::addNegativeVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey());
addError(reply, Reply::NotFoundError, {});
}
} else {
addError(reply, Reply::NetworkError, reply->errorString());
......
......@@ -142,5 +142,6 @@ bool OebbVehicleLayoutParser::parse(const QByteArray &data)
departure.setScheduledDepartureTime(QDateTime::fromString(obj.value(QLatin1String("scheduledDeparture")).toString(), Qt::ISODate));
departure.setScheduledPlatform(platform.name());
return true;
return !platform.sections().empty() || !vehicle.sections().empty()
|| departure.scheduledArrivalTime().isValid() || departure.scheduledDepartureTime().isValid();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment