Added auth
This commit is contained in:
@@ -15,6 +15,12 @@ pub enum ApiError {
|
||||
#[error("bad request: {0}")]
|
||||
BadRequest(String),
|
||||
|
||||
#[error("unauthorized: {0}")]
|
||||
Unauthorized(String),
|
||||
|
||||
#[error("forbidden: {0}")]
|
||||
Forbidden(String),
|
||||
|
||||
#[error("rate limited: {0}")]
|
||||
TooManyRequests(String),
|
||||
|
||||
@@ -27,6 +33,8 @@ impl ResponseError for ApiError {
|
||||
let (status, message) = match self {
|
||||
ApiError::NotFound(msg) => (actix_web::http::StatusCode::NOT_FOUND, msg.clone()),
|
||||
ApiError::BadRequest(msg) => (actix_web::http::StatusCode::BAD_REQUEST, msg.clone()),
|
||||
ApiError::Unauthorized(msg) => (actix_web::http::StatusCode::UNAUTHORIZED, msg.clone()),
|
||||
ApiError::Forbidden(msg) => (actix_web::http::StatusCode::FORBIDDEN, msg.clone()),
|
||||
ApiError::TooManyRequests(msg) => {
|
||||
tracing::warn!(error = %msg, "rate limited");
|
||||
(actix_web::http::StatusCode::TOO_MANY_REQUESTS, msg.clone())
|
||||
|
||||
Reference in New Issue
Block a user