Skip to content

Commit 421488e

Browse files
authored
Error log server response rejections (#2524)
All `ResponseRejection`s are errors; the service owners are to blame. So we centrally log them here to let them know.
1 parent f2abe7c commit 421488e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class ServerHttpBoundProtocolTraitImplGenerator(
135135
"ResponseRejection" to protocol.responseRejection(runtimeConfig),
136136
"PinProjectLite" to ServerCargoDependency.PinProjectLite.toType(),
137137
"http" to RuntimeType.Http,
138+
"Tracing" to RuntimeType.Tracing,
138139
)
139140

140141
fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List<OperationCustomization>) {
@@ -251,17 +252,22 @@ class ServerHttpBoundProtocolTraitImplGenerator(
251252
// Implement `into_response` for output types.
252253
val errorSymbol = symbolProvider.symbolForOperationError(operationShape)
253254

255+
// All `ResponseRejection`s are errors; the service owners are to blame. So we centrally log them here
256+
// to let them know.
254257
rustTemplate(
255258
"""
256259
impl #{SmithyHttpServer}::response::IntoResponse<#{Marker}> for #{O} {
257260
fn into_response(self) -> #{SmithyHttpServer}::response::Response {
258261
match #{serialize_response}(self) {
259262
Ok(response) => response,
260-
Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e))
263+
Err(e) => {
264+
#{Tracing}::error!(error = %e, "failed to serialize response");
265+
#{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e))
266+
}
261267
}
262268
}
263269
}
264-
""".trimIndent(),
270+
""",
265271
*codegenScope,
266272
"O" to outputSymbol,
267273
"Marker" to protocol.markerStruct(),
@@ -278,7 +284,10 @@ class ServerHttpBoundProtocolTraitImplGenerator(
278284
response.extensions_mut().insert(#{SmithyHttpServer}::extension::ModeledErrorExtension::new(self.name()));
279285
response
280286
},
281-
Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e))
287+
Err(e) => {
288+
#{Tracing}::error!(error = %e, "failed to serialize response");
289+
#{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e))
290+
}
282291
}
283292
}
284293
}

0 commit comments

Comments
 (0)