@@ -74,14 +74,23 @@ let nestedPromise =
7474//
7575// Test error handling in fetch
7676
77+ module Fetch = {
78+ @raises (JsError )
79+ let fetch = url => Fetch .fetch (url )
80+
81+ @raises ([])
82+ let status = response => Fetch .Response .status (response )
83+ }
84+
7785let explainError : unknown => string = %raw (` (e )=> e .toString ()` )
7886
7987let testFetch =
8088 @async
8189 (. url ) => {
82- switch {@await Fetch .fetch (url )} {
90+ open Fetch
91+ switch {@await fetch (url )} {
8392 | response =>
84- let status = response -> Fetch . Response . status
93+ let status = response -> status
8594 Js .log2 ("Fetch returned status:" , status )
8695 | exception JsError (e ) => Js .log2 ("Fetch returned an error:" , e -> explainError )
8796 }
@@ -132,7 +141,7 @@ let fetchAndCount = {
132141 (. url ) => {
133142 let response = @await Fetch .fetch (url )
134143 counter := counter .contents + 1
135- (counter .contents , response -> Fetch .Response . status )
144+ (counter .contents , response -> Fetch .status )
136145 }
137146
138147 ff
@@ -177,13 +186,13 @@ let testFetchWithResult =
177186 switch @await
178187 FetchResult .fetch (. "https://www.google.com" ) {
179188 | Ok (response1 ) =>
180- Js .log2 ("FetchResult response1" , response1 -> Fetch .Response . status )
189+ Js .log2 ("FetchResult response1" , response1 -> Fetch .status )
181190 switch nextFetch (. response1 ) {
182191 | None => ()
183192 | Some (url ) =>
184193 switch @await
185194 FetchResult .fetch (. url ) {
186- | Ok (response2 ) => Js .log2 ("FetchResult response2" , response2 -> Fetch .Response . status )
195+ | Ok (response2 ) => Js .log2 ("FetchResult response2" , response2 -> Fetch .status )
187196 | Error (_ ) => ()
188197 }
189198 }
0 commit comments