aws_smithy_http_server_python/middleware/
error.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6use pyo3::{exceptions::PyRuntimeError, PyErr};
7use thiserror::Error;
8
9/// Possible middleware errors that might arise.
10#[derive(Error, Debug)]
11pub enum PyMiddlewareError {
12    #[error("`next` is called multiple times")]
13    NextAlreadyCalled,
14    #[error("request is accessed after `next` is called")]
15    RequestGone,
16    #[error("response is called after it is returned")]
17    ResponseGone,
18}
19
20impl From<PyMiddlewareError> for PyErr {
21    fn from(err: PyMiddlewareError) -> PyErr {
22        PyRuntimeError::new_err(err.to_string())
23    }
24}