[#4] We now properly return error values

master
Jef Roosens 2021-04-03 20:47:39 +02:00
parent e3f134a9bf
commit e3174f21af
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
1 changed files with 7 additions and 7 deletions

View File

@ -3,6 +3,7 @@ mod controller;
mod tests;
use chrono::NaiveDate;
use rocket::http::Status;
use rocket_contrib::json::Json;
pub fn routes() -> Vec<rocket::Route> {
@ -10,21 +11,20 @@ pub fn routes() -> Vec<rocket::Route> {
}
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
// TODO make this async
// TODO change this so it can return errors instead of empty json
#[get("/search?<street>")]
pub fn search_streets_json(street: String) -> Json<Vec<controller::Street>> {
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
match controller::search_streets(&street) {
Ok(streets) => Json(streets),
Err(err) => Json(Vec::new()),
Ok(streets) => Ok(Json(streets)),
Err(err) => Err(Status::InternalServerError),
}
}
#[get("/?<street>&<number>&<start_date>&<end_date>")]
pub fn route_get_pickup_times(
street: controller::Street,
number: u64,
number: u32,
start_date: NaiveDate,
end_date: NaiveDate,
) -> Json<Vec<controller::PickupTime>> {
) -> Result<Json<Vec<controller::PickupTime>>, Status> {
Err(Status::InternalServerError)
}