[MediaWiki-commits] [Gerrit] marvin[master]: Chore: add type checking to error and 404 page props
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/395658 ) Change subject: Chore: add type checking to error and 404 page props .. Chore: add type checking to error and 404 page props Validate that the correct types are passed to the error and not found page modules from the router since these are the only two statically bundled routes. Change-Id: Icdc8aa51bfcb208cec6115e77af81559f833e65c --- M src/common/pages/error.tsx M src/common/router/router.ts 2 files changed, 15 insertions(+), 14 deletions(-) Approvals: Jhernandez: Looks good to me, approved jenkins-bot: Verified diff --git a/src/common/pages/error.tsx b/src/common/pages/error.tsx index 1f85d89..1a13979 100644 --- a/src/common/pages/error.tsx +++ b/src/common/pages/error.tsx @@ -2,7 +2,7 @@ import App from "../components/app/app"; import Page from "../components/page/page"; -interface Props { +export interface Props { error: Error; } diff --git a/src/common/router/router.ts b/src/common/router/router.ts index f208e5b..c4e8d6a 100644 --- a/src/common/router/router.ts +++ b/src/common/router/router.ts @@ -6,9 +6,8 @@ Route } from "../../common/router/route"; import HttpResponse from "../http/http-response"; - -import notFoundPage from "../pages/not-found"; -import errorPage from "../pages/error"; +import notFoundPage, { Props as NotFoundProps } from "../pages/not-found"; +import errorPage, { Props as ErrorProps } from "../pages/error"; import { RedirectError } from "../http/fetch"; export interface RouteResponse { @@ -60,17 +59,23 @@ ); } +function respondNotFound(path: string) { + const props: NotFoundProps = { path }; + return Promise.resolve({ +status: notFoundPage.status, +Component: notFoundPage.Component, +props + }); +} + function respondError(error: Error) { // Throw up RedirectErrors so that they can be handled by the server/client // appropriately if (error instanceof RedirectError) throw error; console.error(`${error.message}\n${error.stack}`); // eslint-disable-line no-console - return { -status: errorPage.status, -Component: errorPage.Component, -props: { error } - }; + const props: ErrorProps = { error }; + return { status: errorPage.status, Component: errorPage.Component, props }; } export const newRouter = ( @@ -85,11 +90,7 @@ return respond(requestPageModule, route, params).catch(respondError); } } - return Promise.resolve({ -status: notFoundPage.status, -Component: notFoundPage.Component, -props: { path } - }); + return respondNotFound(path); } }; }; -- To view, visit https://gerrit.wikimedia.org/r/395658 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icdc8aa51bfcb208cec6115e77af81559f833e65c Gerrit-PatchSet: 6 Gerrit-Project: marvin Gerrit-Branch: master Gerrit-Owner: NiedzielskiGerrit-Reviewer: Jhernandez Gerrit-Reviewer: Sniedzielski Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] marvin[master]: Chore: add type checking to error and 404 page props
Niedzielski has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395658 ) Change subject: Chore: add type checking to error and 404 page props .. Chore: add type checking to error and 404 page props Validate that the correct types are passed to the error and not found page modules from the router since these are the only two statically bundled routes. Change-Id: Icdc8aa51bfcb208cec6115e77af81559f833e65c --- M src/common/pages/error.tsx M src/common/router/router.ts 2 files changed, 15 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/marvin refs/changes/58/395658/1 diff --git a/src/common/pages/error.tsx b/src/common/pages/error.tsx index 1f85d89..1a13979 100644 --- a/src/common/pages/error.tsx +++ b/src/common/pages/error.tsx @@ -2,7 +2,7 @@ import App from "../components/app/app"; import Page from "../components/page/page"; -interface Props { +export interface Props { error: Error; } diff --git a/src/common/router/router.ts b/src/common/router/router.ts index c4b8f45..eaab9d3 100644 --- a/src/common/router/router.ts +++ b/src/common/router/router.ts @@ -6,9 +6,8 @@ Route } from "../../common/router/route"; import HttpResponse from "../http/http-response"; - -import notFoundPage from "../pages/not-found"; -import errorPage from "../pages/error"; +import notFoundPage, { Props as notFoundProps } from "../pages/not-found"; +import errorPage, { Props as errorProps } from "../pages/error"; import { RedirectError } from "../http/fetch"; export interface RouteResponse { @@ -54,17 +53,23 @@ ); } +function respondNotFound(path: string) { + const props: notFoundProps = { path }; + return Promise.resolve({ +status: notFoundPage.status, +Component: notFoundPage.Component, +props + }); +} + function respondError(error: Error) { // Throw up RedirectErrors so that they can be handled by the server/client // appropriately if (error instanceof RedirectError) throw error; console.error(`${error.message}\n${error.stack}`); // eslint-disable-line no-console - return { -status: errorPage.status, -Component: errorPage.Component, -props: { error } - }; + const props: errorProps = { error }; + return { status: errorPage.status, Component: errorPage.Component, props }; } interface PageResolver { @@ -83,11 +88,7 @@ return respond(getPage, route, params).catch(respondError); } } - return Promise.resolve({ -status: notFoundPage.status, -Component: notFoundPage.Component, -props: { path } - }); + return respondNotFound(path); } }; }; -- To view, visit https://gerrit.wikimedia.org/r/395658 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icdc8aa51bfcb208cec6115e77af81559f833e65c Gerrit-PatchSet: 1 Gerrit-Project: marvin Gerrit-Branch: master Gerrit-Owner: NiedzielskiGerrit-Reviewer: Sniedzielski ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits