diff --git a/native/src/lib.rs b/native/src/lib.rs index 611f86e60..74b6ee87f 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -319,9 +319,10 @@ declare_types! { let mut this = cx.this(); - { + let result = { let guard = cx.lock(); let mut pact = this.borrow_mut(&guard); + if let Some(last) = pact.interactions.last_mut() { if let Ok(method) = js_method { match method.downcast::() { @@ -354,10 +355,18 @@ declare_types! { Err(err) => panic!(err) } } + Ok(()) + } else if pact.interactions.is_empty() { + Err("You need to define a new interaction with the uponReceiving method before you can define a new request with the withRequest method") + } else { + Ok(()) } - } + }; - Ok(cx.undefined().upcast()) + match result { + Ok(_) => Ok(cx.undefined().upcast()), + Err(message) => cx.throw_error(message) + } } method addResponse(mut cx) {