Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop serializing server framework-level errors manually #3716

Open
david-perez opened this issue Jun 26, 2024 · 0 comments
Open

Stop serializing server framework-level errors manually #3716

david-perez opened this issue Jun 26, 2024 · 0 comments
Labels
server Rust server SDK

Comments

@david-perez
Copy link
Contributor

We're currently serializing server framework-level errors manually. We're doing this for each protocol. For example, for restJson1:

impl IntoResponse<RestJson1> for RuntimeError {
fn into_response(self) -> http::Response<crate::body::BoxBody> {
let res = http::Response::builder()
.status(self.status_code())
.header("Content-Type", "application/json")
.header("X-Amzn-Errortype", self.name())
.extension(RuntimeErrorExtension::new(self.name().to_string()));
let body = match self {
RuntimeError::Validation(reason) => crate::body::to_boxed(reason),
_ => crate::body::to_boxed("{}"),
};
res.body(body)
.expect(INVALID_HTTP_RESPONSE_FOR_RUNTIME_ERROR_PANIC_MESSAGE)
}
}

Instead of manually writing this serialization code, we should model these errors as Smithy structure shapes with the @error trait, adjoin them automatically to all models, and leverage the code-generated serializers. This is the approach that smithy-typescript uses.

This has the advantage of reducing the amount of code that we need to maintain, and reducing possible bugs introduced in the manual implementations that don't honor the protocol specifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

No branches or pull requests

1 participant