Skip to content

Commit

Permalink
Update service worker fallback (#149)
Browse files Browse the repository at this point in the history
Signed-off-by: Nik Nasr <[email protected]>
  • Loading branch information
nikrooz authored Jan 18, 2025
1 parent 9510243 commit 07fdac8
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 13 deletions.
6 changes: 6 additions & 0 deletions @types/global-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ interface Env {

declare module globalThis {
var env: Env;
var queryFetch:
| undefined
| ((
input: string | URL | globalThis.Request,
init?: RequestInit
) => Promise<Response>);
}
7 changes: 5 additions & 2 deletions libs/data-access/admin-api/src/lib/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import createClient from 'openapi-fetch';

const client = createClient<paths>({
fetch: (...args) => {
return globalThis.fetch(...args);
const fetcher = globalThis.queryFetch ?? globalThis.fetch;
return fetcher(...args);
},
});
const errorMiddleware: Middleware = {
Expand All @@ -30,7 +31,9 @@ const errorMiddleware: Middleware = {
if (typeof body === 'object') {
throw new RestateError(body.message, body.restate_code ?? '');
}
throw new Error(body);
throw new Error(
body || 'An unexpected error occurred. Please try again later.'
);
}
if (response.ok && request.url.endsWith('health')) {
return new Response(JSON.stringify({}), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export async function register() {
});

await navigator.serviceWorker.ready;
return;
} catch (error) {
console.error(`Registration failed with ${error}`);
globalThis.fetch = queryFetcher;
console.warn(`Registration failed with ${error}`);
}
} else {
console.warn('Service Worker not available');
}
globalThis.queryFetch = queryFetcher;
}
3 changes: 2 additions & 1 deletion libs/data-access/middleware-service-worker/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/explainers/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/health/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/invocation-route/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/invocations-route/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/overview-route/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"node",

"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/restate-context/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
3 changes: 2 additions & 1 deletion libs/features/version/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"types": [
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
"@nx/react/typings/image.d.ts",
"../../../@types/global-env.d.ts"
]
},
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@
}
}
},
"packageManager": "[email protected].0"
"packageManager": "[email protected].4"
}

0 comments on commit 07fdac8

Please sign in to comment.