Skip to content

Commit

Permalink
fix: 🚑 corrected serialization from datocms response
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelemedici committed May 21, 2024
1 parent 6e97d5d commit 113f3fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Wrangler",
"type": "node",
"request": "attach",
"port": 9229,
"cwd": "/",
"resolveSourceMapLocations": null,
"attachExistingChildren": false,
"autoAttachChildProcesses": false,
"sourceMaps": true // works with or without this line
}
]
}
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main(mut req: Request, env: Env, _ctx: Context) -> Result<Response> {

let bearer = match env.secret("BEARER_TOKEN") {
Ok(value) => value.to_string(),
Err(err) => return Response::error(format!("Internal Server Error: {err}"), 500),
Err(err) => return Response::error(format!("Error loading env variable: {err}"), 500),
};

let res = client
Expand All @@ -26,19 +26,22 @@ async fn main(mut req: Request, env: Env, _ctx: Context) -> Result<Response> {
.await;

let response_body = match res {
Ok(response) => match response.bytes().await {
Ok(bytes) => bytes.to_vec(),
Err(err) => return Response::error(format!("Internal Server Error: {err}"), 500),
},
Ok(value) => value,
Err(err) => return Response::error(format!("Internal Server Error: {err}"), 500),
};

let serialized: FestivalsResponse = match serde_json::from_slice(&response_body) {
let response_body = match response_body.bytes().await {
Ok(value) => value,
Err(err) => return Response::error(format!("Internal Server Error: {err}"), 500),
};

let origins = ["https://trippavisor.it", "https://dev.trippavisor.it"];
let serialized: FestivalData = match serde_json::from_slice(&response_body) {
Ok(value) => value,
Err(err) => return Response::error(format!("Serialization error: {err}"), 500),
};

let origins = ["*"];

let cors_headers: Vec<&str> = vec!["Content-Type"];

let cors = Cors::default()
Expand Down

0 comments on commit 113f3fe

Please sign in to comment.