Skip to main content

wrap_handler_result

Function wrap_handler_result 

Source
pub fn wrap_handler_result(
    result: Result<Value, DurableError>,
) -> Result<Value, Box<dyn Error + Send + Sync>>
Expand description

Wrap a handler result into the durable execution invocation output format.

Converts Result<serde_json::Value, DurableError> into the {"Status": ...} envelope that the AWS Lambda Durable Execution service expects as the Lambda function response.

§Status Mapping

InputOutput
Ok(value){"Status": "SUCCEEDED", "Result": "<serialized value>"}
Err(StepRetryScheduled | WaitSuspended | CallbackSuspended | InvokeSuspended){"Status": "PENDING"}
Err(other){"Status": "FAILED", "Error": {"ErrorMessage": "...", "ErrorType": "..."}}

§Returns

Always returns Ok(serde_json::Value) — the caller must never treat this as an error, since the durable execution protocol uses the response body to signal all outcomes including failures.

§Examples

use durable_lambda_core::response::wrap_handler_result;
use durable_lambda_core::error::DurableError;

// Success case
let result = Ok(serde_json::json!({"order_id": "123"}));
let output = wrap_handler_result(result).unwrap();
assert_eq!(output["Status"], "SUCCEEDED");

// Suspension case (PENDING)
let result: Result<serde_json::Value, DurableError> =
    Err(DurableError::wait_suspended("cooldown"));
let output = wrap_handler_result(result).unwrap();
assert_eq!(output["Status"], "PENDING");

// Failure case
let result: Result<serde_json::Value, DurableError> =
    Err(DurableError::step_timeout("slow_op"));
let output = wrap_handler_result(result).unwrap();
assert_eq!(output["Status"], "FAILED");