Skip to content

Commit

Permalink
fix: throw an exception when a request is configured but no interacti…
Browse files Browse the repository at this point in the history
…on defined
  • Loading branch information
Ronald Holshausen committed May 12, 2020
1 parent 8463bf6 commit b317da7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<JsString>() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b317da7

Please sign in to comment.