aws_smithy_http_server/schema/modeled_error.rs
1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6use aws_smithy_schema::serde::SerializableStruct;
7
8/// A modeled error that a [`ServerProtocol`](super::ServerProtocol) can turn into an HTTP response.
9pub trait HttpModeledError: SerializableStruct + std::error::Error + Send + Sync + 'static {
10 /// The HTTP status code for this error: `@httpError` when present, otherwise `400` for
11 /// `@error("client")` shapes and `500` for `@error("server")` shapes.
12 fn status_code(&self) -> u16;
13
14 /// The operation that returned this error, when known.
15 ///
16 /// Generated operation error enums expose their operation's input, output, and
17 /// error schemas. Shared error structures and errors created outside an operation
18 /// have no operation context. Each protocol decides whether to use this context.
19 fn operation_schema(&self) -> Option<&super::OperationSchema<'_>> {
20 None
21 }
22}
23
24// Operations without modeled errors use Infallible. These methods can never be called.
25impl HttpModeledError for std::convert::Infallible {
26 fn status_code(&self) -> u16 {
27 match *self {}
28 }
29}