File tree Expand file tree Collapse file tree 2 files changed +27
-15
lines changed Expand file tree Collapse file tree 2 files changed +27
-15
lines changed Original file line number Diff line number Diff 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-
4045module ClientOnly = {
4146 @react.component
4247 let make = (~bundleBaseUrl , ~versions ) => {
@@ -47,12 +52,19 @@ module ClientOnly = {
4752}
4853
4954let 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}
Original file line number Diff line number Diff 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
88let default : unit => React .element
You can’t perform that action at this time.
0 commit comments