Skip to content

Commit

Permalink
Show II migration page if II canister returns an error
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed Oct 17, 2022
1 parent b640141 commit ade4c55
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions typescript/service-worker/src/pages/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const html = (strings: TemplateStringsArray, ...values: unknown[]) =>
String.raw({ raw: strings }, ...values);
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { html } from './html';

export const internetIdentityMaintenanceTemplate = (
errorMessage: string
) => html`
<html>
<head>
<meta charset="utf8" />
<title>Internet Identity Maintenance</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
body {
text-align: center;
font-size: 16px;
padding: 5em 1em 1em;
box-sizing: border-box;
font-family: sans-serif;
display: flex;
flex-flow: column nowrap;
justify-content: space-between;
}
</style>
</head>
<body>
<main>
<h1>Internet Identity is under maintenance</h1>
<p>
Visit the
<a href="https://forum.dfinity.org/">
Internet Computer Developer Forum
</a>
for relevant announcements.
</p>
<p>Error details:</p>
<code> ${errorMessage} </code>
</main>
</body>
</html>
`;
12 changes: 12 additions & 0 deletions typescript/service-worker/src/sw/http_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../http-interface/canister_http_interface_types';
import { idlFactory } from '../http-interface/canister_http_interface';
import { streamContent } from './streaming';
import { internetIdentityMaintenanceTemplate } from '../pages/internet-identity-maintenance';

const hostnameCanisterIdMap: Record<string, [string, string]> = {
'identity.ic0.app': ['rdmx6-jaaaa-aaaaa-aaadq-cai', 'ic0.app'],
Expand Down Expand Up @@ -452,6 +453,17 @@ export async function handleRequest(request: Request): Promise<Response> {
}
} catch (e) {
console.error('Failed to fetch response:', e);

if (
['rdmx6-jaaaa-aaaaa-aaadq-cai', 'y2aaj-miaaa-aaaad-aacxq-cai'].includes(
maybeCanisterId.toString()
)
) {
return new Response(internetIdentityMaintenanceTemplate(String(e)), {
headers: { 'Content-Type': 'text/html' },
});
}

return new Response(`Failed to fetch response: ${String(e)}`, {
status: 500,
});
Expand Down

0 comments on commit ade4c55

Please sign in to comment.