diff --git a/packages/common/api-helper/build/src/error.rs b/packages/common/api-helper/build/src/error.rs index 4ea78e4d90..a2220daf36 100644 --- a/packages/common/api-helper/build/src/error.rs +++ b/packages/common/api-helper/build/src/error.rs @@ -1,3 +1,4 @@ +use chirp_workflow::prelude::WorkflowError; use chrono::TimeZone; use global_error::prelude::*; use headers::HeaderValue; @@ -26,6 +27,14 @@ pub fn handle_rejection( mut response: http::response::Builder, ray_id: Uuid, ) -> Result, http::Error> { + // TODO: Remove panic + let verbose_errors = config + .server() + .expect("missing server") + .rivet + .api_public + .verbose_errors(); + // Log error let err = match err { GlobalError::BadRequest { .. } => { @@ -37,36 +46,43 @@ pub fn handle_rejection( // Replace internal errors with global errors // TODO: Remove panic - if config - .server() - .expect("missing server") - .rivet - .api_public - .verbose_errors() - { + if verbose_errors { err_code!(ERROR, error = err.to_string()) } else { err_code!(ERROR, error = "An internal error has occurred.",) } } GlobalError::Raw(err) => { - tracing::error!(?err, "internal error response"); + // Check if this is a workflow error that wraps a global error + match err.downcast::().map(|x| *x) { + Ok(WorkflowError::OperationFailure(global_err)) => { + // Handle unwrapped error + return handle_rejection(config, global_err, response, ray_id); + } + Ok(err) => { + tracing::error!(?err, "internal error response"); - // Replace internal errors with global errors - // TODO: Remove panic - if config - .server() - .expect("missing server") - .rivet - .api_public - .verbose_errors() - { - err_code!(ERROR, error = err.to_string()) - } else { - err_code!( - ERROR, - error = format!("An internal error has occurred (ray_id {}).", ray_id) - ) + if verbose_errors { + err_code!(ERROR, error = err.to_string()) + } else { + err_code!( + ERROR, + error = format!("An internal error has occurred (ray_id {}).", ray_id) + ) + } + } + Err(err) => { + tracing::error!(?err, "internal error response"); + + if verbose_errors { + err_code!(ERROR, error = err.to_string()) + } else { + err_code!( + ERROR, + error = format!("An internal error has occurred (ray_id {}).", ray_id) + ) + } + } } } }; diff --git a/packages/common/formatted-error/build.rs b/packages/common/formatted-error/build.rs index 4113ed649e..095d0c57cd 100644 --- a/packages/common/formatted-error/build.rs +++ b/packages/common/formatted-error/build.rs @@ -178,7 +178,7 @@ fn visit_dir(ctx: &mut Ctx, path: PathBuf) -> std::io::Result<()> { } }) .collect::(); - let documentation = format!("https://rivet.gg/docs/general/errors#{clean_title}"); + let documentation = format!("https://rivet.gg/docs/api/errors#{clean_title}"); ctx.hash_items.push(formatdoc!( "