blob: ffa4cca1249c1a41a14cef67282056a41bb086b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
use hyper::{header::ToStrError, Body, Response, StatusCode};
pub struct WebhookError {
pub code: StatusCode,
pub message: String,
}
impl WebhookError {
pub fn new(code: StatusCode, message: &str) -> WebhookError {
WebhookError {
code,
message: message.to_string(),
}
}
}
impl From<WebhookError> for Response<Body> {
fn from(value: WebhookError) -> Self {
Response::builder()
.status(value.code)
.body(value.message.into())
.unwrap()
}
}
impl From<hyper::Error> for WebhookError {
fn from(_: hyper::Error) -> Self {
WebhookError::new(StatusCode::BAD_REQUEST, "invalid request")
}
}
impl From<ToStrError> for WebhookError {
fn from(_: ToStrError) -> Self {
WebhookError::new(StatusCode::BAD_REQUEST, "invalid request")
}
}
|