Skip to content

Commit fd2ae09

Browse files
committed
add an error message when compiler versions can't be loaded
1 parent c9f5d44 commit fd2ae09

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

app/routes/TryRoute.res

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@ let loader = async () => {
2222
)
2323
}
2424

25-
let versions = {
26-
let response = await fetch(versionsBaseUrl + "/playground-bundles/versions.json")
27-
let json = await WebAPI.Response.json(response)
28-
json
29-
->JSON.Decode.array
30-
->Option.getOrThrow
31-
->Array.map(json => json->JSON.Decode.string->Option.getOrThrow)
32-
}
25+
try {
26+
let versions = {
27+
let response = await fetch(versionsBaseUrl + "/playground-bundles/versions.json")
28+
let json = await WebAPI.Response.json(response)
29+
json
30+
->JSON.Decode.array
31+
->Option.getOrThrow
32+
->Array.map(json => json->JSON.Decode.string->Option.getOrThrow)
33+
}
3334

34-
{
35-
bundleBaseUrl,
36-
versions,
35+
Some({
36+
bundleBaseUrl,
37+
versions,
38+
})
39+
} catch {
40+
| JsExn(e) =>
41+
Console.error2("error while fetching compiler versions", e)
42+
None
3743
}
3844
}
39-
4045
module ClientOnly = {
4146
@react.component
4247
let make = (~bundleBaseUrl, ~versions) => {
@@ -47,12 +52,19 @@ module ClientOnly = {
4752
}
4853

4954
let default = () => {
50-
let {bundleBaseUrl, versions} = ReactRouter.useLoaderData()
55+
let data = ReactRouter.useLoaderData()
5156
<>
5257
<Meta
5358
title="ReScript Playground" description="Try ReScript in the browser" ogImage="/og/try.png"
5459
/>
5560

56-
<ClientOnly bundleBaseUrl versions />
61+
{switch data {
62+
| Some({bundleBaseUrl, versions}) => <ClientOnly bundleBaseUrl versions />
63+
| None =>
64+
<div className="mt-16 p-5 text-xl text-red-500 self-center">
65+
<h1> {React.string("Oops an error occurred!")} </h1>
66+
{React.string("The playground cannot be loaded, please try again in a few moments.")}
67+
</div>
68+
}}
5769
</>
5870
}

app/routes/TryRoute.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ type props = {
33
versions: array<string>,
44
}
55

6-
let loader: unit => promise<props>
6+
let loader: unit => promise<option<props>>
77

88
let default: unit => React.element

0 commit comments

Comments
 (0)