Commit 51ee3957 authored by Volker Krause's avatar Volker Krause
Browse files

Forward XML parsing errors as OJP parsing errors

parent 9fe1eeab
<?xml version="1.0" encoding="UTF-8"?>
<siri:OJP xmlns:siri="http://www.siri.org.uk/siri" xmlns:ojp="http://www.vdv.de/ojp" version="1.0"><siri:OJPResponse><siri:ServiceDelivery><siri:ResponseTimestamp>
......@@ -138,13 +138,25 @@ private Q_SLOTS:
void testParseError()
{
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
const auto res = p.parseTripResponse(readFile(s(SOURCE_DIR "/data/ojp/ch-error-notripfound.xml")));
QVERIFY(res.empty());
QVERIFY(p.hasError());
QCOMPARE(p.errorMessage(), QLatin1String("TRIP_NOTRIPFOUND"));
{
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
auto res = p.parseTripResponse(readFile(s(SOURCE_DIR "/data/ojp/ch-error-notripfound.xml")));
QVERIFY(res.empty());
QVERIFY(p.hasError());
QCOMPARE(p.errorMessage(), QLatin1String("TRIP_NOTRIPFOUND"));
}
{
OpenJourneyPlannerParser p;
p.setLocationIdentifierType(QStringLiteral("test_id"));
p.setUicLocationIdentifierType(QStringLiteral("uic"));
auto res = p.parseStopEventResponse(readFile(s(SOURCE_DIR "/data/ojp/xml-error.xml")));
QVERIFY(res.empty());
QVERIFY(p.hasError());
QCOMPARE(p.errorMessage(), QLatin1String("Premature end of document."));
}
}
};
......
......@@ -46,36 +46,48 @@ std::vector<Location> OpenJourneyPlannerParser::parseLocationInformationResponse
{
QXmlStreamReader reader(responseData);
ScopedXmlStreamReader r(reader);
std::vector<Location> res;
while (r.readNextElement()) {
if (r.isElement("OJPLocationInformationDelivery") || r.isElement("LocationInformationResponse")) {
return parseLocationInformationDelivery(r.subReader());
res = parseLocationInformationDelivery(r.subReader());
}
}
return {};
if (reader.hasError() && m_errorMsg.isEmpty()) {
m_errorMsg = reader.errorString();
}
return res;
}
std::vector<Stopover> OpenJourneyPlannerParser::parseStopEventResponse(const QByteArray &responseData)
{
QXmlStreamReader reader(responseData);
ScopedXmlStreamReader r(reader);
std::vector<Stopover> res;
while (r.readNextElement()) {
if (r.isElement("OJPStopEventDelivery") || r.isElement("StopEventResponse")) {
return parseStopEventDelivery(r.subReader());
res = parseStopEventDelivery(r.subReader());
}
}
return {};
if (reader.hasError() && m_errorMsg.isEmpty()) {
m_errorMsg = reader.errorString();
}
return res;
}
std::vector<Journey> OpenJourneyPlannerParser::parseTripResponse(const QByteArray &responseData)
{
QXmlStreamReader reader(responseData);
ScopedXmlStreamReader r(reader);
std::vector<Journey> res;
while (r.readNextElement()) {
if (r.isElement("OJPTripDelivery") || r.isElement("TripResponse")) {
return parseTripDelivery(r.subReader());
res = parseTripDelivery(r.subReader());
}
}
return {};
if (reader.hasError() && m_errorMsg.isEmpty()) {
m_errorMsg = reader.errorString();
}
return res;
}
std::vector<Location> OpenJourneyPlannerParser::parseLocationInformationDelivery(ScopedXmlStreamReader &&r)
......
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