fix api respond

This commit is contained in:
kimpure 2026-05-19 18:26:30 +00:00
parent f24cfdceaa
commit 2f4885305e
No known key found for this signature in database
2 changed files with 10 additions and 5 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use axum::{Json, extract::State};
use axum::{Json, extract::State, http::StatusCode};
use crate::tts::TtsPool;
use serde::{Deserialize, Serialize};
@ -15,8 +15,9 @@ pub struct Body {
pub async fn handler(
State(state): State<Arc<TtsPool>>,
Json(payload): Json<Body>,
) -> Result<Vec<u8>, String> {
) -> Result<Vec<u8>, (StatusCode, String)> {
Ok(state
.synthesize(payload.text, payload.lang, payload.style_id)
.await?)
.await
.map_err(|err| (StatusCode::BAD_REQUEST, err))?)
}

View file

@ -55,8 +55,12 @@ impl TtsPool {
let start_at = Instant::now();
let Some(style) = style_map.get(&job.style_id) else {
job.reply
.send(Err(format!("Voice style {} not found", job.style_id)));
if let Err(_) = job
.reply
.send(Err(format!("Voice style {} not found", job.style_id)))
{
tracing::error!("Worker send error");
}
continue;
};