@@ -74,14 +74,23 @@ let nestedPromise =
74
74
//
75
75
// Test error handling in fetch
76
76
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
+
77
85
let explainError : unknown => string = %raw (` (e )=> e .toString ()` )
78
86
79
87
let testFetch =
80
88
@async
81
89
(. url ) => {
82
- switch {@await Fetch .fetch (url )} {
90
+ open Fetch
91
+ switch {@await fetch (url )} {
83
92
| response =>
84
- let status = response -> Fetch . Response . status
93
+ let status = response -> status
85
94
Js .log2 ("Fetch returned status:" , status )
86
95
| exception JsError (e ) => Js .log2 ("Fetch returned an error:" , e -> explainError )
87
96
}
@@ -132,7 +141,7 @@ let fetchAndCount = {
132
141
(. url ) => {
133
142
let response = @await Fetch .fetch (url )
134
143
counter := counter .contents + 1
135
- (counter .contents , response -> Fetch .Response . status )
144
+ (counter .contents , response -> Fetch .status )
136
145
}
137
146
138
147
ff
@@ -177,13 +186,13 @@ let testFetchWithResult =
177
186
switch @await
178
187
FetchResult .fetch (. "https://www.google.com" ) {
179
188
| Ok (response1 ) =>
180
- Js .log2 ("FetchResult response1" , response1 -> Fetch .Response . status )
189
+ Js .log2 ("FetchResult response1" , response1 -> Fetch .status )
181
190
switch nextFetch (. response1 ) {
182
191
| None => ()
183
192
| Some (url ) =>
184
193
switch @await
185
194
FetchResult .fetch (. url ) {
186
- | Ok (response2 ) => Js .log2 ("FetchResult response2" , response2 -> Fetch .Response . status )
195
+ | Ok (response2 ) => Js .log2 ("FetchResult response2" , response2 -> Fetch .status )
187
196
| Error (_ ) => ()
188
197
}
189
198
}
0 commit comments