Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions examples/auth-provider/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ft-sdk/src/from_request/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub fn handle<T, O: Into<Result<http::Response<bytes::Bytes>, ft_sdk::Error>>, H: Handler<T, O>>(
h: H,
) {
ft_sdk::println!("Handling request with handler");
let req = match current_request() {
Ok(v) => v,
Err(e) => {
Expand All @@ -12,7 +13,7 @@ pub fn handle<T, O: Into<Result<http::Response<bytes::Bytes>, ft_sdk::Error>>, H
}
};
let resp = h.call(&req).and_then(Into::into).unwrap_or_else(|e| {
ft_sdk::println!("Error: {:?}", e);
ft_sdk::println!("Error1: {:?}", e);
ft_sdk::error::handle_error(e)
});
ft_sdk::http::send_response(resp);
Expand Down
21 changes: 19 additions & 2 deletions ft-sdk/src/from_request/required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,42 @@ impl<const KEY: &'static str, T: serde::de::DeserializeOwned + 'static> ft_sdk::
for Required<KEY, T>
{
fn from_request(req: &http::Request<serde_json::Value>) -> Result<Self, ft_sdk::Error> {
match req.body() {
ft_sdk::println!(
"Required<{}, {}>::from_request",
KEY,
std::any::type_name::<T>()
);
let r = match req.body() {
serde_json::Value::Null => {
ft_sdk::println!("body is Null, expected Object");
Err(ft_sdk::single_error(KEY, "body is Null, expected Object").into())
}
serde_json::Value::Object(map) => {
ft_sdk::println!("body is Object, checking for key: {}", KEY);
if let Some(value) = map.get(KEY) {
ft_sdk::println!("found key: {}", KEY);
if std::any::TypeId::of::<T>() == std::any::TypeId::of::<String>() {
ft_sdk::println!("type is String, checking if empty");
if let serde_json::Value::String(s) = value {
if s.is_empty() {
return Err(ft_sdk::single_error(KEY, "field is empty").into());
}
}
} else {
ft_sdk::println!("type is not String");
if let serde_json::Value::String(s) = value {
return Ok(serde_json::from_str(s).map(Required)?);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even tho this code path is interesting and we should keep it. This is not hit when running inside lets-teach code. I am going to remove redundant println! from this PR and we can merge this :)

}
ft_sdk::println!("deserializing {KEY}={value:?}");
Ok(serde_json::from_value(value.clone()).map(Required)?)
} else {
Err(ft_sdk::single_error(KEY, "missing field").into())
}
}
_ => Err(ft_sdk::single_error(KEY, "body is not json object").into()),
}
};
ft_sdk::println!("r: {:?}", r.is_err());
r
}
}
2 changes: 1 addition & 1 deletion ft-sys/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn print_it(s: String) {
#[doc(hidden)]
#[cfg(not(target_family = "wasm"))]
pub fn print_it(s: String) {
println!("{s}");
println!("wasm: {s}");
}

/// Print some data to the server log.
Expand Down
Loading