Add API error type
This commit is contained in:
parent
32e99b155c
commit
0006004db1
1 changed files with 9 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue