Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions packages/common/api-helper/build/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chirp_workflow::prelude::WorkflowError;
use chrono::TimeZone;
use global_error::prelude::*;
use headers::HeaderValue;
Expand Down Expand Up @@ -26,6 +27,14 @@ pub fn handle_rejection(
mut response: http::response::Builder,
ray_id: Uuid,
) -> Result<Response<Body>, 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 { .. } => {
Expand All @@ -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::<WorkflowError>().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)
)
}
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/common/formatted-error/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn visit_dir(ctx: &mut Ctx, path: PathBuf) -> std::io::Result<()> {
}
})
.collect::<String>();
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!(
"
Expand Down
Loading