Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openapi #280

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ actix-cors = "0.7.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
validator = { version = "0.16", features = ["derive"] }
thiserror = "2.0"

## FINAL
sysinfo = "0.29"
Expand Down
55 changes: 55 additions & 0 deletions src/lib/server/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use actix_web::{http::StatusCode, ResponseError};

use paperclip::actix::api_v2_errors;
use validator::ValidationErrors;

pub type Result<T> = actix_web::Result<T, Error>;

#[allow(dead_code)]
#[api_v2_errors(
code = 400,
description = "Bad Request: The client's request contains invalid or malformed data.",
code = 404,
description = "Not Found: The requested path or entity does not exist.",
code = 500,
description = "Internal Server Error: An unexpected server error has occurred.",
code = 503,
description = "Service Unavailable: ."
)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Bad Request: {0}")]
BadRequest(String),

#[error("Not Found: {0}")]
NotFound(String),

#[error("Internal Server Error: {0}")]
Internal(String),

#[error("Service Unavailable: {0}")]
Unavailable(String),
}

impl ResponseError for Error {
fn status_code(&self) -> StatusCode {
match self {
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
Self::NotFound(_) => StatusCode::NOT_FOUND,
Self::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR,
Self::Unavailable(_) => StatusCode::SERVICE_UNAVAILABLE,
}
}
}

impl From<ValidationErrors> for Error {
fn from(error: ValidationErrors) -> Self {
Self::BadRequest(error.to_string())
}
}

impl From<actix_web_validator::Error> for Error {
fn from(error: actix_web_validator::Error) -> Self {
Self::BadRequest(error.to_string())
}
}
1 change: 1 addition & 0 deletions src/lib/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod error;
pub mod manager;
mod pages;
Loading
Loading