mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-04-30 10:39:09 +00:00
handle error in sse event route
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use esp_println::dbg;
|
use esp_println::dbg;
|
||||||
|
use log::error;
|
||||||
use picoserve::{
|
use picoserve::{
|
||||||
extract::{Json, Query, State},
|
extract::{Json, Query, State},
|
||||||
response::{self, IntoResponse},
|
response::{self, IntoResponse},
|
||||||
@@ -44,8 +45,19 @@ pub async fn add_mapping(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SSE /api/idevent
|
// SSE /api/idevent
|
||||||
pub async fn get_idevent(State(state): State<AppState>) -> impl IntoResponse {
|
pub async fn get_idevent(
|
||||||
response::EventStream(IDEvents(state.chan.subscriber().unwrap()))
|
State(state): State<AppState>,
|
||||||
|
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||||
|
match state.chan.subscriber() {
|
||||||
|
Ok(chan) => Ok(response::EventStream(IDEvents(chan))),
|
||||||
|
Err(e) => {
|
||||||
|
error!("Failed to create SSE: {:?}", e);
|
||||||
|
Err((
|
||||||
|
response::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
"Internal server error",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/days
|
// GET /api/days
|
||||||
@@ -68,7 +80,6 @@ pub async fn get_day(
|
|||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Query(QueryDay { timestamp, day }): Query<QueryDay>,
|
Query(QueryDay { timestamp, day }): Query<QueryDay>,
|
||||||
) -> Result<impl IntoResponse, impl IntoResponse> {
|
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||||
|
|
||||||
let parsed_day = timestamp
|
let parsed_day = timestamp
|
||||||
.map(Day::new_from_timestamp)
|
.map(Day::new_from_timestamp)
|
||||||
.or_else(|| day.map(Day::new))
|
.or_else(|| day.map(Day::new))
|
||||||
|
|||||||
Reference in New Issue
Block a user