Skip to content

Commit

Permalink
send error msg in return for debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Rajat Jindal <[email protected]>
  • Loading branch information
rajatjindal committed Jul 5, 2023
1 parent 3e75c42 commit 89e63c8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/testcases/config-variables/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Result};
use anyhow::Result;
use spin_sdk::{
config,
http::{Request, Response},
Expand All @@ -12,15 +12,21 @@ fn handle_request(req: Request) -> Result<Response> {
.query()
.expect("Should have a password query string");
let query: std::collections::HashMap<String, String> = serde_qs::from_str(query)?;
let provided_password = query
let expected_password = query
.get("password")
.expect("Should have a password query string");
let expected_password = config::get("password")?;
let actual_password = config::get("password")?;

ensure!(
provided_password == &expected_password,
"password must match expected"
);
if expected_password != &actual_password {
let error_msg = format!(
"expected password: '{}', actual password: '{}'",
expected_password, &actual_password
);

return Ok(http::Response::builder()
.status(401)
.body(Some(error_msg.into()))?);
}

Ok(http::Response::builder().status(200).body(None)?)
}

0 comments on commit 89e63c8

Please sign in to comment.