jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/395571 )

Change subject: Chore: replace fetch header type assertion
......................................................................


Chore: replace fetch header type assertion

Replace fetch header type assumption with runtime check.

Change-Id: I4d90844c170281059c433ae84f3fe1a00d0cf835
---
M src/common/http/fetch.ts
1 file changed, 9 insertions(+), 6 deletions(-)

Approvals:
  Niedzielski: Looks good to me, approved
  Jhernandez: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/common/http/fetch.ts b/src/common/http/fetch.ts
index 3bca889..958072a 100644
--- a/src/common/http/fetch.ts
+++ b/src/common/http/fetch.ts
@@ -7,8 +7,8 @@
   status: number;
   url: string;
 
-  constructor(status: number, url: string) {
-    super();
+  constructor(status: number, url: string, message?: string) {
+    super(message);
     this.status = status;
     this.url = url;
   }
@@ -39,16 +39,19 @@
   // code so "manual" is used instead.
   const redirect = server ? "manual" : undefined;
   return fetch(input, { redirect, ...init }).then(response => {
+    const requestURL = typeof input === "string" ? input : input.url;
     if (server && response.status >= 300 && response.status <= 399) {
       const url = response.headers.get("location");
-      throw new RedirectError(response.status, url as string);
+      if (url) throw new RedirectError(response.status, url);
+
+      const message = "Location header missing in service response.";
+      throw new ServerError(500, requestURL, message);
     }
-    const url = typeof input === "string" ? input : input.url;
     if (response.status >= 400 && response.status <= 499) {
-      throw new ClientError(response.status, url);
+      throw new ClientError(response.status, requestURL);
     }
     if (response.status >= 500) {
-      throw new ServerError(response.status, url);
+      throw new ServerError(response.status, requestURL);
     }
     return response;
   });

-- 
To view, visit https://gerrit.wikimedia.org/r/395571
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4d90844c170281059c433ae84f3fe1a00d0cf835
Gerrit-PatchSet: 6
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Niedzielski <[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

Reply via email to