summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu <matthieu@developershouse.xyz>2021-10-14 21:06:48 +0000
committerMatthieu <matthieu@developershouse.xyz>2021-10-14 21:06:48 +0000
commit8250b77a23b1a4f3102dcb9fe43a745f752462ce (patch)
treedf9f55efed151d2604af1434136fc684ce7e0e25
parent2617665dab8901c6d994c6805a66a3e8fac24924 (diff)
fix gihub ci
-rw-r--r--gateway/src/shard/connection.rs2
-rw-r--r--webhook/src/handler/handler.rs53
2 files changed, 36 insertions, 19 deletions
diff --git a/gateway/src/shard/connection.rs b/gateway/src/shard/connection.rs
index 2f7f2d5..8f8ddc6 100644
--- a/gateway/src/shard/connection.rs
+++ b/gateway/src/shard/connection.rs
@@ -7,7 +7,7 @@ use crate::{connection::Connection, error::GatewayError, payloads::{
use super::{state::ConnectionState, ConnectionWithState, Shard};
use futures::StreamExt;
-use common::{log::{error, info}};
+use common::log::{error, info};
use tokio::{select, time::{Instant, interval_at, sleep}};
impl Shard {
diff --git a/webhook/src/handler/handler.rs b/webhook/src/handler/handler.rs
index bcce81d..4af2ba6 100644
--- a/webhook/src/handler/handler.rs
+++ b/webhook/src/handler/handler.rs
@@ -42,39 +42,52 @@ impl HandlerService {
) {
Ok(data)
} else {
- Err(WebhookError::new(StatusCode::UNAUTHORIZED, "invalid signature"))
+ Err(WebhookError::new(
+ StatusCode::UNAUTHORIZED,
+ "invalid signature",
+ ))
}
} else {
- Err(WebhookError::new(StatusCode::BAD_REQUEST, "failed to read signature"))
+ Err(WebhookError::new(
+ StatusCode::BAD_REQUEST,
+ "failed to read signature",
+ ))
}
} else {
- Err(WebhookError::new(StatusCode::BAD_REQUEST, "unable to read body"))
+ Err(WebhookError::new(
+ StatusCode::BAD_REQUEST,
+ "unable to read body",
+ ))
}
} else {
- Err(WebhookError::new(StatusCode::UNAUTHORIZED, "missing signature headers"))
+ Err(WebhookError::new(
+ StatusCode::UNAUTHORIZED,
+ "missing signature headers",
+ ))
}
} else {
Err(WebhookError::new(StatusCode::NOT_FOUND, "not found"))
}
}
-
- async fn process_request(&mut self, req: Request<Body>) -> Result<Response<Body>, WebhookError> {
+ async fn process_request(
+ &mut self,
+ req: Request<Body>,
+ ) -> Result<Response<Body>, WebhookError> {
match self.check_request(req).await {
Ok(data) => {
let utf8 = from_utf8(&data);
match utf8 {
Ok(data) => match serde_json::from_str::<Interaction>(data) {
- Ok(value) => match value.t {
- 1 => {
+ Ok(value) => {
+ if value.t == 1 {
info!("sending pong");
// a ping must be responded with another ping
return Ok(Response::builder()
.header("Content-Type", "application/json")
.body(serde_json::to_string(&Ping { t: 1 }).unwrap().into())
.unwrap());
- }
- _ => {
+ } else {
debug!("calling nats");
// this should hopefully not fail ?
let payload =
@@ -95,20 +108,24 @@ impl HandlerService {
) {
Ok(response) => Ok(Response::builder()
.header("Content-Type", "application/json")
- .body(
- Body::from(response.data)
- )
+ .body(Body::from(response.data))
.unwrap()),
-
+
Err(error) => {
error!("failed to request nats: {}", error);
- Err(WebhookError::new(StatusCode::INTERNAL_SERVER_ERROR, "failed to request nats"))
+ Err(WebhookError::new(
+ StatusCode::INTERNAL_SERVER_ERROR,
+ "failed to request nats",
+ ))
}
}
}
- },
+ }
- Err(_) => Err(WebhookError::new(StatusCode::BAD_REQUEST, "invalid json body")),
+ Err(_) => Err(WebhookError::new(
+ StatusCode::BAD_REQUEST,
+ "invalid json body",
+ )),
},
Err(_) => Err(WebhookError::new(StatusCode::BAD_REQUEST, "not utf-8 body")),
@@ -142,7 +159,7 @@ impl Service<Request<Body>> for HandlerService {
match response {
Ok(r) => Ok(r),
- Err(e) => Ok(e.into())
+ Err(e) => Ok(e.into()),
}
})
}