404 handler
This commit is contained in:
parent
03057706f8
commit
03295580e3
@ -35,3 +35,8 @@ pub struct ConvertURLRequest {
|
|||||||
pub url: String,
|
pub url: String,
|
||||||
pub callback_url: Option<String>,
|
pub callback_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub(crate) struct ErrorResponse {
|
||||||
|
pub(crate) error: String
|
||||||
|
}
|
@ -15,7 +15,7 @@ use tower_http::trace::TraceLayer;
|
|||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::dto::{ConvertRequest, ConvertResponse, ConvertURLRequest};
|
use crate::dto::{ConvertRequest, ConvertResponse, ConvertURLRequest, ErrorResponse};
|
||||||
use crate::task::{Task, TaskParams};
|
use crate::task::{Task, TaskParams};
|
||||||
use crate::thread_pool::ThreadPool;
|
use crate::thread_pool::ThreadPool;
|
||||||
|
|
||||||
@ -73,7 +73,8 @@ impl Server {
|
|||||||
.route("/enqueue_url", post(enqueue_url))
|
.route("/enqueue_url", post(enqueue_url))
|
||||||
.route("/get/:identifier", get(download_file))
|
.route("/get/:identifier", get(download_file))
|
||||||
.with_state(this)
|
.with_state(this)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http())
|
||||||
|
.fallback(handler_not_found);
|
||||||
|
|
||||||
tracing::info!("listening on {addr}");
|
tracing::info!("listening on {addr}");
|
||||||
let listener = TcpListener::bind(addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
@ -220,6 +221,10 @@ async fn download_file(
|
|||||||
Ok(([(http::header::CONTENT_TYPE, mime_type)], body))
|
Ok(([(http::header::CONTENT_TYPE, mime_type)], body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handler_not_found() -> impl IntoResponse {
|
||||||
|
(StatusCode::NOT_FOUND, Json::from(ErrorResponse { error: "not found".to_string() }))
|
||||||
|
}
|
||||||
|
|
||||||
fn error_response(msg: &str) -> (StatusCode, Json<ConvertResponse>) {
|
fn error_response(msg: &str) -> (StatusCode, Json<ConvertResponse>) {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
@ -4,11 +4,10 @@ use ffmpeg_next::channel_layout::ChannelLayout;
|
|||||||
use ffmpeg_next::{format, Dictionary};
|
use ffmpeg_next::{format, Dictionary};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
use ureq::Error as UreqError;
|
use ureq::Error as UreqError;
|
||||||
use ureq::Response;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
|
Loading…
Reference in New Issue
Block a user