Error handling

This commit is contained in:
2023-09-04 20:15:05 -04:00
parent 9db32e4d5a
commit cf3ee4feef
10 changed files with 182 additions and 105 deletions

View File

@@ -1,16 +1,27 @@
use crate::error_handler::CustomError;
use crate::metars::Metars;
use actix_web::{get, web, HttpResponse};
use actix_web::{get, web, HttpResponse, Responder};
// #[get("metars/{ids}")]
// async fn get_all(ids: web::Path<String>) -> Result<HttpResponse, CustomError> {
// let airports = web::block(|| Ok::<_, CustomError>(async {Metars::get_all(ids.into_inner()).await}))
// .await
// .unwrap()
// .unwrap()
// .await
// .unwrap();
// Ok(HttpResponse::Ok().json(airports))
// }
#[get("metars/{ids}")]
async fn get_all(ids: web::Path<String>) -> Result<HttpResponse, CustomError> {
async fn get_all(ids: web::Path<String>) -> impl Responder {
let airports = web::block(|| Ok::<_, CustomError>(async {Metars::get_all(ids.into_inner()).await}))
.await
.unwrap()
.unwrap()
.await
.unwrap();
Ok(HttpResponse::Ok().json(airports))
HttpResponse::Ok().json(airports)
}
pub fn init_routes(config: &mut web::ServiceConfig) {