Add API error type

This commit is contained in:
Xiretza 2024-02-10 10:49:36 +00:00
parent 32e99b155c
commit 0006004db1

View file

@ -1,6 +1,5 @@
use axum::{
extract::Query,
response::ErrorResponse,
routing::{get, post},
Form, Json, Router,
};
@ -20,6 +19,14 @@ pub async fn run() -> color_eyre::Result<()> {
Ok(())
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
struct ApiError {
error: String,
message: String,
}
type ApiResult<T> = Result<T, Json<ApiError>>;
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
struct ApiVersion {
api_version: String,
@ -41,7 +48,7 @@ struct LoginResponse {
async fn api_login(
Query(ApiVersion { api_version }): Query<ApiVersion>,
Form(LoginRequest { username, password }): Form<LoginRequest>,
) -> Result<Json<LoginResponse>, ErrorResponse> {
) -> ApiResult<Json<LoginResponse>> {
event!(Level::WARN, "Creating dummy token");
Ok(Json(LoginResponse {