Account for poem 1.2 breaking changes
Signed-off-by: Jim Crossley <jim@crossleys.org>
This commit is contained in:
parent
7f538a3f37
commit
24bbf941b1
|
|
@ -47,7 +47,7 @@ http = { version = "0.2", optional = true }
|
||||||
hyper = { version = "^0.14", optional = true }
|
hyper = { version = "^0.14", optional = true }
|
||||||
axum-lib = { version = "^0.2", optional = true, package = "axum" }
|
axum-lib = { version = "^0.2", optional = true, package = "axum" }
|
||||||
http-body = { version = "^0.4", optional = true }
|
http-body = { version = "^0.4", optional = true }
|
||||||
poem-lib = { version = "1.0.23", optional = true, package = "poem" }
|
poem-lib = { version = "1", optional = true, package = "poem" }
|
||||||
|
|
||||||
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
|
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
|
||||||
hostname = "^0.3"
|
hostname = "^0.3"
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,20 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use poem_lib::error::ReadBodyError;
|
use poem_lib::error::ResponseError;
|
||||||
use poem_lib::http::StatusCode;
|
use poem_lib::http::StatusCode;
|
||||||
use poem_lib::{FromRequest, IntoResponse, Request, RequestBody, Response};
|
use poem_lib::{FromRequest, Request, RequestBody, Result};
|
||||||
|
|
||||||
use crate::binding::http::to_event;
|
use crate::binding::http::to_event;
|
||||||
use crate::Event;
|
use crate::Event;
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl ResponseError for crate::message::Error {
|
||||||
pub enum ParseEventError {
|
fn status(&self) -> StatusCode {
|
||||||
ReadBody(ReadBodyError),
|
StatusCode::BAD_REQUEST
|
||||||
ParseEvent(crate::message::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ReadBodyError> for ParseEventError {
|
|
||||||
fn from(err: ReadBodyError) -> Self {
|
|
||||||
ParseEventError::ReadBody(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<crate::message::Error> for ParseEventError {
|
|
||||||
fn from(err: crate::message::Error) -> Self {
|
|
||||||
ParseEventError::ParseEvent(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoResponse for ParseEventError {
|
|
||||||
fn into_response(self) -> Response {
|
|
||||||
match self {
|
|
||||||
ParseEventError::ReadBody(err) => err.into_response(),
|
|
||||||
ParseEventError::ParseEvent(err) => (StatusCode::BAD_REQUEST, err.to_string()).into(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'a> FromRequest<'a> for Event {
|
impl<'a> FromRequest<'a> for Event {
|
||||||
type Error = ParseEventError;
|
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self> {
|
||||||
|
|
||||||
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self, Self::Error> {
|
|
||||||
Ok(to_event(req.headers(), body.take()?.into_vec().await?)?)
|
Ok(to_event(req.headers(), body.take()?.into_vec().await?)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,12 +56,9 @@ mod tests {
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
let (req, mut body) = req.split();
|
let (req, mut body) = req.split();
|
||||||
let resp = Event::from_request(&req, &mut body).await.into_response();
|
let resp = Event::from_request(&req, &mut body).await.err().unwrap();
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
assert_eq!(
|
assert_eq!(resp.to_string(), "Invalid specversion BAD SPECIFICATION");
|
||||||
resp.into_body().into_string().await.unwrap(),
|
|
||||||
"Invalid specversion BAD SPECIFICATION"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
|
|
@ -55,5 +55,3 @@
|
||||||
|
|
||||||
mod extractor;
|
mod extractor;
|
||||||
mod response;
|
mod response;
|
||||||
|
|
||||||
pub use extractor::ParseEventError;
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue