Skip to content

Commit

Permalink
fix: if query parameters are not supplied they will be null or undefi…
Browse files Browse the repository at this point in the history
…ned #516
  • Loading branch information
Ronald Holshausen committed Nov 16, 2020
1 parent 190f332 commit 17397be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions native/src/lib.rs
Expand Up @@ -209,10 +209,10 @@ fn get_parameter(cx: &mut CallContext<JsPact>, param: &Handle<JsValue>) -> NeonR
}

fn process_query(cx: &mut CallContext<JsPact>, js_query: Handle<JsValue>, request: Handle<JsObject>) -> NeonResult<(HashMap<String, Vec<String>>, MatchingRuleCategory, HashMap<String, Generator>)> {
let mut map = hashmap!{};
let mut rules = MatchingRuleCategory::empty("query");
let mut generators = hashmap!{};
if let Ok(query_map) = js_query.downcast::<JsObject>() {
let mut map = hashmap!{};
let mut rules = MatchingRuleCategory::empty("query");
let mut generators = hashmap!{};
let props = query_map.get_own_property_names(cx)?;
for prop in props.to_vec(cx).unwrap() {
let prop_name = prop.downcast::<JsString>().unwrap().value();
Expand Down Expand Up @@ -243,6 +243,8 @@ fn process_query(cx: &mut CallContext<JsPact>, js_query: Handle<JsValue>, reques
}
}
Ok((map, rules, generators))
} else if js_query.is_a::<JsUndefined>() || js_query.is_a::<JsNull>() {
Ok((map, rules, generators))
} else {
cx.throw_type_error(format!("Query parameters must be a map of key/values"))
}
Expand Down

0 comments on commit 17397be

Please sign in to comment.