Skip to content

Commit 4c4a2b0

Browse files
authored
Add debug assertions check to streaming (#635)
This is used by Cargo Lambda's local server to control req/response. Signed-off-by: David Calavera <[email protected]>
1 parent 2654433 commit 4c4a2b0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lambda-runtime/src/streaming.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ where
108108
let event = next_event_response?;
109109
let (parts, body) = event.into_parts();
110110

111+
#[cfg(debug_assertions)]
112+
if parts.status == http::StatusCode::NO_CONTENT {
113+
// Ignore the event if the status code is 204.
114+
// This is a way to keep the runtime alive when
115+
// there are no events pending to be processed.
116+
continue;
117+
}
118+
111119
let ctx: Context = Context::try_from(parts.headers)?;
112120
let ctx: Context = ctx.with_config(config);
113121
let request_id = &ctx.request_id.clone();
@@ -128,6 +136,12 @@ where
128136
let body = hyper::body::to_bytes(body).await?;
129137
trace!("incoming request payload - {}", std::str::from_utf8(&body)?);
130138

139+
#[cfg(debug_assertions)]
140+
if parts.status.is_server_error() {
141+
error!("Lambda Runtime server returned an unexpected error");
142+
return Err(parts.status.to_string().into());
143+
}
144+
131145
let body = match serde_json::from_slice(&body) {
132146
Ok(body) => body,
133147
Err(err) => {

0 commit comments

Comments
 (0)