Skip to content

Commit c2e3a6e

Browse files
Merge pull request #150 from code0-tech/#149-wrong-http-signature
made http status code to i64
2 parents 291b370 + 6a8c0a1 commit c2e3a6e

4 files changed

Lines changed: 20 additions & 15 deletions

File tree

crates/core/src/context/argument.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::convert::Infallible;
44
use tucana::shared::value::Kind;
55
use tucana::shared::{ListValue, NumberValue, Struct, Value};
66

7-
use crate::value::number_to_f64;
7+
use crate::value::{number_to_f64, number_to_i64_lossy};
88
#[derive(Clone, Debug)]
99
pub enum Argument {
1010
// Eval => Evaluated Value
@@ -52,6 +52,17 @@ impl TryFromArgument for NumberValue {
5252
}
5353
}
5454

55+
impl TryFromArgument for i64 {
56+
fn try_from_argument(a: &Argument) -> Result<Self, Signal> {
57+
match a {
58+
Argument::Eval(Value {
59+
kind: Some(Kind::NumberValue(n)),
60+
}) => number_to_i64_lossy(n).ok_or_else(|| type_err("Expected number", a)),
61+
_ => Err(type_err("Expected number", a)),
62+
}
63+
}
64+
}
65+
5566
impl TryFromArgument for f64 {
5667
fn try_from_argument(a: &Argument) -> Result<Self, Signal> {
5768
match a {

crates/core/src/runtime/functions/http.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,9 @@ fn create_response(
114114
_ctx: &mut Context,
115115
_run: &mut dyn FnMut(i64, &mut Context) -> Signal,
116116
) -> Signal {
117-
args!(args => http_status_code: String, headers: Struct, payload: Value);
117+
args!(args => http_status_code: i64, headers: Struct, payload: Value);
118118
let mut fields = std::collections::HashMap::new();
119-
120-
let code = match http_status_code.as_str().parse::<i64>() {
121-
Ok(c) => c,
122-
Err(_) => {
123-
return Signal::Failure(RuntimeError::simple_str(
124-
"InvalidArgumentExeption",
125-
"Expected http_status_code to be parsed to integer",
126-
));
127-
}
128-
};
129-
fields.insert("status_code".to_string(), value_from_i64(code));
119+
fields.insert("status_code".to_string(), value_from_i64(http_status_code));
130120

131121
fields.insert(
132122
"headers".to_string(),

flows/01_return_object.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"runtimeParameterId": "http_status_code",
4343
"value": {
4444
"literalValue": {
45-
"stringValue": "200"
45+
"numberValue": {
46+
"integer": "200"
47+
}
4648
}
4749
}
4850
},

flows/02_return_flow_input.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
"runtimeParameterId": "http_status_code",
5555
"value": {
5656
"literalValue": {
57-
"stringValue": "200"
57+
"numberValue": {
58+
"integer": "200"
59+
}
5860
}
5961
}
6062
},

0 commit comments

Comments
 (0)