From 8f515ccf758a91deb1533704ccc0960dbb857e35 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Mon, 24 Apr 2023 02:46:02 +0200 Subject: [PATCH] Moved mqtt parse error to error.rs --- src/error.rs | 7 +++++++ src/mqtt.rs | 13 ++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 19d7d73..3c3ab6c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ use std::{error, fmt, result}; use axum::{http::status::InvalidStatusCode, response::IntoResponse}; +use bytes::Bytes; use rumqttc::ClientError; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -57,6 +58,12 @@ impl fmt::Display for MissingEnv { impl error::Error for MissingEnv {} +#[derive(Debug, Error)] +pub enum ParseError { + #[error("Invalid message payload received: {0:?}")] + InvalidPayload(Bytes), +} + #[derive(Debug, Error)] pub enum ConfigParseError { #[error(transparent)] diff --git a/src/mqtt.rs b/src/mqtt.rs index b362afd..23846c9 100644 --- a/src/mqtt.rs +++ b/src/mqtt.rs @@ -1,19 +1,14 @@ use std::time::{SystemTime, UNIX_EPOCH}; -use bytes::Bytes; use serde::{Deserialize, Serialize}; -use thiserror::Error; use tracing::{debug, warn}; use rumqttc::{Event, EventLoop, Incoming, Publish}; -use crate::event::{self, EventChannel}; - -#[derive(Debug, Error)] -pub enum ParseError { - #[error("Invalid message payload received: {0:?}")] - InvalidPayload(Bytes), -} +use crate::{ + error::ParseError, + event::{self, EventChannel}, +}; pub fn start(mut eventloop: EventLoop, event_channel: &EventChannel) { let tx = event_channel.get_tx();