feat: handle errors in deploy endpoint
This commit is contained in:
parent
4b43c4ed3d
commit
eb87453bd1
3 changed files with 11 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -997,6 +997,7 @@ dependencies = [
|
|||
"pretty_env_logger",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
|
|
@ -35,5 +35,7 @@ derive_more = "0.99"
|
|||
|
||||
num_cpus = "1.13"
|
||||
|
||||
tokio = { version = "1", features=["sync"]}
|
||||
|
||||
[dev-dependencies]
|
||||
mktemp = "0.4.1"
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
*/
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::errors::*;
|
||||
use crate::SETTINGS;
|
||||
|
||||
pub mod routes {
|
||||
|
@ -40,24 +42,21 @@ pub struct DeployEvent {
|
|||
}
|
||||
|
||||
#[my_codegen::post(path = "crate::V1_API_ROUTES.deploy.update")]
|
||||
async fn update(payload: web::Json<DeployEvent>) -> impl Responder {
|
||||
let mut found = false;
|
||||
async fn update(payload: web::Json<DeployEvent>) -> ServiceResult<impl Responder> {
|
||||
for page in SETTINGS.pages.iter() {
|
||||
if page.secret == payload.secret {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
web::block(|| {
|
||||
page.update();
|
||||
tx.send(page.update()).unwrap();
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
found = true;
|
||||
rx.await.unwrap()?;
|
||||
return Ok(HttpResponse::Ok());
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
HttpResponse::Ok()
|
||||
} else {
|
||||
HttpResponse::NotFound()
|
||||
}
|
||||
Err(ServiceError::WebsiteNotFound)
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
|
Loading…
Reference in a new issue