jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/396015 )
Change subject: Fix: visiting a missing wiki page causes a server error
......................................................................
Fix: visiting a missing wiki page causes a server error
instanceof comparisons to FetchError and subclasses were failing due to
a bad prototype chain. Explicitly call Object.setPrototypeOf() as
recommended in the docs.
Bug: T181900
Change-Id: I8747716e45bc1c697e3cb0fa8b3b250f808b14e6
---
M package.json
M src/client/tsconfig.json
M src/common/http/fetch.ts
M src/common/pages/home.tsx
4 files changed, 37 insertions(+), 42 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/package.json b/package.json
index 88be03a..c0e4eb9 100644
--- a/package.json
+++ b/package.json
@@ -120,7 +120,7 @@
},
{
"path": "dist/public/pages/home.*.js",
- "maxSize": "0.8KB"
+ "maxSize": "0.9KB"
},
{
"path": "dist/public/pages/summary.*.js",
diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json
index 864986b..77c7513 100644
--- a/src/client/tsconfig.json
+++ b/src/client/tsconfig.json
@@ -11,6 +11,6 @@
// https://github.com/Microsoft/TypeScript/issues/16675
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/15020
"module": "esnext",
- "lib": [ "es5", "es2015.iterable", "es2015.promise", "dom" ]
+ "lib": ["es5", "es2015.core", "es2015.iterable", "es2015.promise", "dom"]
}
}
diff --git a/src/common/http/fetch.ts b/src/common/http/fetch.ts
index 4bc5024..f6e6e06 100644
--- a/src/common/http/fetch.ts
+++ b/src/common/http/fetch.ts
@@ -12,17 +12,37 @@
super(message);
this.status = status;
this.url = url;
+
+ // Fix instanceof usages in ES5 (here and in subclasses). See:
+ // -
https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
+ // -
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
+ Object.setPrototypeOf(this, FetchError.prototype);
}
}
/** Server-only 3xx redirect status code and destination URL. */
-export class RedirectError extends FetchError {}
+export class RedirectError extends FetchError {
+ constructor(status: number, url: string, message?: string) {
+ super(status, url, message);
+ Object.setPrototypeOf(this, RedirectError.prototype);
+ }
+}
/** 4xx status code errors. */
-export class ClientError extends FetchError {}
+export class ClientError extends FetchError {
+ constructor(status: number, url: string, message?: string) {
+ super(status, url, message);
+ Object.setPrototypeOf(this, ClientError.prototype);
+ }
+}
/** 5xx status code errors. */
-export class ServerError extends FetchError {}
+export class ServerError extends FetchError {
+ constructor(status: number, url: string, message?: string) {
+ super(status, url, message);
+ Object.setPrototypeOf(this, ServerError.prototype);
+ }
+}
/**
* Isomorphic fetch with transparent throw-on-redirect behavior for requests
diff --git a/src/common/pages/home.tsx b/src/common/pages/home.tsx
index 0df9bcc..2c38d5f 100644
--- a/src/common/pages/home.tsx
+++ b/src/common/pages/home.tsx
@@ -14,49 +14,23 @@
import Link from "../components/link/link";
const testSummaries = [
- {
- title: "Banana",
- text: "With landscape image"
- },
- {
- title: "Cucumber",
- text: "With portrait image"
- },
- {
- title: "Plaintext",
- text: "Without image"
- },
+ { title: "Banana", text: "With landscape image" },
+ { title: "Cucumber", text: "With portrait image" },
+ { title: "Plaintext", text: "Without image" },
{
title: "Bill_&_Ted's_Excellent_Adventure",
text: "With two paragraphs, unencoded path, and styled title"
},
- {
- title: "Carrot cake",
- text: "Encoding redirect (301)"
- },
- {
- title: "Cheese_cake",
- text: "Redirect page (302)"
- }
+ { title: "Carrot cake", text: "Encoding redirect (301)" },
+ { title: "Cheese_cake", text: "Redirect page (302)" },
+ { title: "Nonexistent_title", text: "Missing (404)" }
];
const testPages = [
- {
- title: "Ice_cream",
- text: "A normal article"
- },
- {
- title: "Cake_(disambiguation)",
- text: "Disambiguation"
- },
- {
- title: "Carrot cake",
- text: "Encoding redirect (301)"
- },
- {
- title: "Cheese_cake",
- text: "Redirect page (302)"
- },
+ { title: "Ice_cream", text: "A normal article" },
+ { title: "Cake_(disambiguation)", text: "Disambiguation" },
+ { title: "Carrot cake", text: "Encoding redirect (301)" },
+ { title: "Cheese_cake", text: "Redirect page (302)" },
{
title: "Ice_cream_cake",
revision: "24242119",
@@ -65,7 +39,8 @@
{
title: "File:Vanilla_Ice_Cream_Cone_at_Camp_Manitoulin.jpg",
text: "Redirect (external) and File page"
- }
+ },
+ { title: "Nonexistent_title", text: "Missing (404)" }
];
export default {
--
To view, visit https://gerrit.wikimedia.org/r/396015
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8747716e45bc1c697e3cb0fa8b3b250f808b14e6
Gerrit-PatchSet: 3
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits