Skip to content

Commit

Permalink
fix: return null for missing settings without 404
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 19, 2023
1 parent 728c00e commit d39f258
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion aw-server/src/endpoints/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rocket::State;
use std::collections::HashMap;
use std::sync::MutexGuard;

use aw_datastore::Datastore;
use aw_datastore::{Datastore, DatastoreError};

use crate::endpoints::HttpErrorJson;

Expand Down Expand Up @@ -57,6 +57,7 @@ pub fn setting_get(

match datastore.get_key_value(&setting_key) {
Ok(value) => Ok(Json(serde_json::from_str(&value).unwrap())),
Err(DatastoreError::NoSuchKey(_)) => Ok(Json(serde_json::from_str("null").unwrap())),
Err(err) => Err(err.into()),
}
}
Expand Down
8 changes: 5 additions & 3 deletions aw-server/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ mod api_tests {
}

#[test]
fn test_getting_not_found_value() {
fn test_get_unset_setting() {
let server = setup_testserver();
let client = Client::untracked(server).expect("valid instance");

Expand All @@ -523,7 +523,8 @@ mod api_tests {
.get(format!("/api/0/settings/{}", key))
.header(Header::new("Host", "127.0.0.1:5600"))
.dispatch();
assert_eq!(res.status(), rocket::http::Status::NotFound);
assert_eq!(res.status(), rocket::http::Status::Ok);
assert_eq!(res.into_string().unwrap(), "null")
}

#[test]
Expand Down Expand Up @@ -664,7 +665,8 @@ mod api_tests {
.get("/api/0/settings/test_key")
.header(Header::new("Host", "127.0.0.1:5600"))
.dispatch();
assert_eq!(res.status(), rocket::http::Status::NotFound);
assert_eq!(res.status(), rocket::http::Status::Ok);
assert_eq!(res.into_string().unwrap(), "null");
}

#[test]
Expand Down

0 comments on commit d39f258

Please sign in to comment.