1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

use pyo3::{exceptions::PyRuntimeError, PyErr};
use thiserror::Error;

/// Possible middleware errors that might arise.
#[derive(Error, Debug)]
pub enum PyMiddlewareError {
    #[error("`next` is called multiple times")]
    NextAlreadyCalled,
    #[error("request is accessed after `next` is called")]
    RequestGone,
    #[error("response is called after it is returned")]
    ResponseGone,
}

impl From<PyMiddlewareError> for PyErr {
    fn from(err: PyMiddlewareError) -> PyErr {
        PyRuntimeError::new_err(err.to_string())
    }
}