mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-26 08:01:38 +00:00
feat(backend): add windmill_status_code to run_wait_result
This commit is contained in:
@@ -1421,6 +1421,13 @@ async fn run_wait_result<T>(
|
||||
}
|
||||
if let Some(result) = result {
|
||||
g.done = true;
|
||||
let status_code = result
|
||||
.get("windmill_status_code")
|
||||
.and_then(|x| x.as_i64())
|
||||
.and_then(|x| StatusCode::from_u16(x as u16).ok());
|
||||
if let Some(status_code) = status_code {
|
||||
return Err(Error::CustomStatusCode(status_code, result));
|
||||
}
|
||||
Ok(Json(result))
|
||||
} else {
|
||||
Err(Error::ExecutionErr(format!("timeout after {}s", timeout)))
|
||||
|
||||
@@ -13,6 +13,7 @@ use axum::{
|
||||
response::Json,
|
||||
};
|
||||
|
||||
use hyper::StatusCode;
|
||||
#[cfg(feature = "sqlx")]
|
||||
use sqlx::migrate::MigrateError;
|
||||
use thiserror::Error;
|
||||
@@ -60,6 +61,8 @@ pub enum Error {
|
||||
Anyhow(#[from] anyhow::Error),
|
||||
#[error("Error: {0:#?}")]
|
||||
JsonErr(serde_json::Value),
|
||||
#[error("Custom Status Code: {0:#?}")]
|
||||
CustomStatusCode(StatusCode, serde_json::Value),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -82,6 +85,7 @@ impl IntoResponse for Error {
|
||||
Self::NotFound(_) => axum::http::StatusCode::NOT_FOUND,
|
||||
Self::NotAuthorized(_) => axum::http::StatusCode::UNAUTHORIZED,
|
||||
Self::RequireAdmin(_) => axum::http::StatusCode::FORBIDDEN,
|
||||
Self::CustomStatusCode(code, _) => code,
|
||||
Self::SqlErr(_) | Self::BadRequest(_) => axum::http::StatusCode::BAD_REQUEST,
|
||||
_ => axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user