BearND has uploaded a new change for review.
https://gerrit.wikimedia.org/r/235649
Change subject: Avoid exceptions when there is an API error.
......................................................................
Avoid exceptions when there is an API error.
Bug: T111114
Change-Id: Icdceb776bfe951626ce6462dfc60d2f93ccf4013
---
M routes/mobile-html-sections.js
1 file changed, 26 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps
refs/changes/49/235649/1
diff --git a/routes/mobile-html-sections.js b/routes/mobile-html-sections.js
index 73ada98..012d5bb 100644
--- a/routes/mobile-html-sections.js
+++ b/routes/mobile-html-sections.js
@@ -45,20 +45,22 @@
function pageContentPromise(domain, title) {
return mwapi.getAllSections(domain, title)
.then(function (response) {
- // transform all sections
- var sections = response.body.mobileview.sections;
- for (var idx = 0; idx < sections.length; idx++) {
- var section = sections[idx];
- section.text = transforms.runDomTransforms(section.text, idx);
- }
+ if (response.body.mobileview) {
+ var sections = response.body.mobileview.sections;
- if (!response.body.mobileview.mainpage) {
- // don't do anything if this is the main page, since many wikis
- // arrange the main page in a series of tables.
- // TODO: should we also exclude file and other special pages?
- sections[0].text =
transforms.moveFirstParagraphUpInLeadSection(sections[0].text);
- }
+ // transform all sections
+ for (var idx = 0; idx < sections.length; idx++) {
+ var section = sections[idx];
+ section.text = transforms.runDomTransforms(section.text, idx);
+ }
+ if (!response.body.mobileview.mainpage) {
+ // don't do anything if this is the main page, since many wikis
+ // arrange the main page in a series of tables.
+ // TODO: should we also exclude file and other special pages?
+ sections[0].text =
transforms.moveFirstParagraphUpInLeadSection(sections[0].text);
+ }
+ }
return response.body.mobileview;
});
}
@@ -83,6 +85,10 @@
}
function buildLead(input) {
+ if (!input.page) {
+ return {};
+ }
+
var lead = domino.createDocument(input.page.sections[0].text);
return {
id: input.page.id,
@@ -105,12 +111,20 @@
}
function buildRemaining(input) {
+ if (!input.page) {
+ return {};
+ }
+
return {
sections: input.page.sections.slice(1) // don't repeat the first
section
};
}
function buildAll(input) {
+ if (!input.page) {
+ return {};
+ }
+
return {
lead: buildLead(input),
remaining: buildRemaining(input)
--
To view, visit https://gerrit.wikimedia.org/r/235649
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdceb776bfe951626ce6462dfc60d2f93ccf4013
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits