8484{
8585 fn from ( fut : ApiFuture < T > ) -> Self {
8686 future_to_promise ( async move {
87- let x = Ok ( fut. 0 . await ?) ;
88- let y = Ok ( x. into_js_result ( ) ?) ;
89- Ok ( y. ignore_view_delete ( ) ?)
87+ fut. 0
88+ . await
89+ . map_err ( |x| x. into ( ) )
90+ . into_js_result ( )
91+ . ignore_view_delete ( )
9092 } )
9193 }
9294}
@@ -146,7 +148,7 @@ where
146148static CANCELLED_MSG : & str = "View method cancelled" ;
147149
148150#[ extend:: ext]
149- pub impl Result < JsValue , ApiError > {
151+ pub impl Result < JsValue , JsValue > {
150152 /// Wraps an error `JsValue` return from a caught JavaScript exception,
151153 /// checking for the explicit error type indicating that a
152154 /// `JsPerspectiveView` call has been cancelled due to it already being
@@ -160,35 +162,22 @@ pub impl Result<JsValue, ApiError> {
160162 /// silently be replaced with `Ok`. The message itself is returned in this
161163 /// case (instead of whatever the `async` returns), which is helpful for
162164 /// detecting this condition when debugging.
165+ fn ignore_view_delete ( self ) -> Result < JsValue , JsValue > {
166+ self . or_else ( |x| match x. dyn_ref :: < PerspectiveViewNotFoundError > ( ) {
167+ Some ( _) => Ok ( js_intern:: js_intern!( CANCELLED_MSG ) . clone ( ) ) ,
168+ None => Err ( x) ,
169+ } )
170+ }
171+ }
172+
173+ #[ extend:: ext]
174+ pub impl Result < JsValue , ApiError > {
163175 fn ignore_view_delete ( self ) -> Result < JsValue , ApiError > {
164176 self . or_else ( |x| {
165177 let f: JsValue = x. clone ( ) . into ( ) ;
166- match f. dyn_ref :: < js_sys:: Error > ( ) {
167- Some ( err) => {
168- if err. message ( ) != CANCELLED_MSG {
169- Err ( x)
170- } else {
171- Ok ( js_intern:: js_intern!( CANCELLED_MSG ) . clone ( ) )
172- }
173- } ,
174- _ => match f. as_string ( ) {
175- Some ( x) if x == CANCELLED_MSG => {
176- Ok ( js_intern:: js_intern!( CANCELLED_MSG ) . clone ( ) )
177- } ,
178- Some ( _) => Err ( x) ,
179- _ => {
180- if js_sys:: Reflect :: get ( & f, js_intern:: js_intern!( "message" ) )
181- . unwrap ( )
182- . as_string ( )
183- . unwrap_or_else ( || "" . to_owned ( ) )
184- == CANCELLED_MSG
185- {
186- Ok ( js_intern:: js_intern!( CANCELLED_MSG ) . clone ( ) )
187- } else {
188- Err ( x)
189- }
190- } ,
191- } ,
178+ match f. dyn_ref :: < PerspectiveViewNotFoundError > ( ) {
179+ Some ( _) => Ok ( js_intern:: js_intern!( CANCELLED_MSG ) . clone ( ) ) ,
180+ None => Err ( x) ,
192181 }
193182 } )
194183 }
0 commit comments