[#9] Added general error module
This commit is contained in:
parent
a80774b341
commit
eab31e5e91
4 changed files with 29 additions and 5 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use crate::errors::FejError;
|
||||
use regex::Regex;
|
||||
use reqwest::blocking as reqwest;
|
||||
use rocket::http::RawStr;
|
||||
|
|
@ -73,7 +74,7 @@ pub struct Street {
|
|||
/// * `street` - name of the street
|
||||
/// * `city` - city the street is in
|
||||
// TODO find out how to do this async
|
||||
pub fn search_streets(street_name: &String) -> Result<Vec<Street>, Box<dyn Error>> {
|
||||
pub fn search_streets(street_name: &String) -> Result<Vec<Street>, FejError> {
|
||||
let client = reqwest::Client::new();
|
||||
let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?;
|
||||
let data: Vec<HashMap<String, String>> = response.json()?;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ mod controller;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use crate::errors::FejError;
|
||||
use rocket::http::Status;
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
|
|
@ -12,10 +13,8 @@ pub fn routes() -> Vec<rocket::Route> {
|
|||
// URL: https://www.ivago.be/nl/particulier/autocomplete/garbage/streets?q=Lange
|
||||
#[get("/search?<street>")]
|
||||
pub fn route_search_streets(street: String) -> Result<Json<Vec<controller::Street>>, Status> {
|
||||
match controller::search_streets(&street) {
|
||||
Ok(streets) => Ok(Json(streets)),
|
||||
Err(_) => Err(Status::InternalServerError),
|
||||
}
|
||||
let result = controller::search_streets(&street)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
#[get("/?<street>&<number>&<start_date>&<end_date>")]
|
||||
|
|
|
|||
Reference in a new issue