mirror of
https://github.com/Xevion/time-banner.git
synced 2025-12-06 01:16:36 -06:00
Add fallback route handler
This commit is contained in:
@@ -6,6 +6,7 @@ pub enum TimeBannerError {
|
||||
ParseError(String),
|
||||
RenderError(String),
|
||||
RasterizeError(String),
|
||||
NotFound,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -18,7 +19,8 @@ pub fn get_error_response(error: TimeBannerError) -> (StatusCode, Json<ErrorResp
|
||||
let (code, message) = match error {
|
||||
TimeBannerError::RenderError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, format!("RenderError :: {}", msg)),
|
||||
TimeBannerError::ParseError(msg) => (StatusCode::BAD_REQUEST, format!("ParserError :: {}", msg)),
|
||||
TimeBannerError::RasterizeError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, format!("RasertizeError :: {}", msg))
|
||||
TimeBannerError::RasterizeError(msg) => (StatusCode::INTERNAL_SERVER_ERROR, format!("RasterizeError :: {}", msg)),
|
||||
TimeBannerError::NotFound => { (StatusCode::NOT_FOUND, "Not Found".to_string()) }
|
||||
};
|
||||
|
||||
(code, Json(ErrorResponse { code: code.as_u16(), message }))
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use axum::response::IntoResponse;
|
||||
use dotenvy::dotenv;
|
||||
use config::Configuration;
|
||||
use crate::routes::{relative_handler, implicit_handler, absolute_handler, index_handler};
|
||||
use crate::error::{get_error_response, TimeBannerError};
|
||||
use crate::routes::{relative_handler, implicit_handler, absolute_handler, index_handler, fallback_handler};
|
||||
|
||||
mod config;
|
||||
mod raster;
|
||||
@@ -34,7 +36,8 @@ async fn main() {
|
||||
.route("/rel/:path", get(relative_handler))
|
||||
.route("/relative/:path", get(relative_handler))
|
||||
.route("/absolute/:path", get(absolute_handler))
|
||||
.route("/abs/:path", get(absolute_handler));
|
||||
.route("/abs/:path", get(absolute_handler))
|
||||
.fallback(fallback_handler);
|
||||
|
||||
let addr = SocketAddr::from((config.socket_addr(), config.port));
|
||||
axum::Server::bind(&addr)
|
||||
|
||||
@@ -43,6 +43,10 @@ pub async fn relative_handler(Path(path): Path<String>) -> impl IntoResponse {
|
||||
let (raw_time, extension) = parse_path(path.as_str());
|
||||
}
|
||||
|
||||
pub async fn fallback_handler() -> impl IntoResponse {
|
||||
return get_error_response(TimeBannerError::NotFound).into_response();
|
||||
}
|
||||
|
||||
pub async fn absolute_handler(Path(path): Path<String>) -> impl IntoResponse {
|
||||
let (raw_time, extension) = parse_path(path.as_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user