Compare commits
1 Commits
32b4b533c0
...
1f36374394
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f36374394 |
28
src/error.rs
28
src/error.rs
@@ -15,6 +15,9 @@ pub enum ApiError {
|
||||
#[error("bad request: {0}")]
|
||||
BadRequest(String),
|
||||
|
||||
#[error("rate limited: {0}")]
|
||||
TooManyRequests(String),
|
||||
|
||||
#[error("internal error: {0}")]
|
||||
Internal(String),
|
||||
}
|
||||
@@ -24,6 +27,10 @@ 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::TooManyRequests(msg) => {
|
||||
tracing::warn!(error = %msg, "rate limited");
|
||||
(actix_web::http::StatusCode::TOO_MANY_REQUESTS, msg.clone())
|
||||
}
|
||||
ApiError::Internal(msg) => {
|
||||
tracing::error!(error = %msg, "internal error");
|
||||
(
|
||||
@@ -63,6 +70,27 @@ impl From<shanty_search::SearchError> for ApiError {
|
||||
|
||||
impl From<shanty_dl::DlError> for ApiError {
|
||||
fn from(e: shanty_dl::DlError) -> Self {
|
||||
match e {
|
||||
shanty_dl::DlError::RateLimited(msg) => ApiError::TooManyRequests(msg),
|
||||
other => ApiError::Internal(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<shanty_index::IndexError> for ApiError {
|
||||
fn from(e: shanty_index::IndexError) -> Self {
|
||||
ApiError::Internal(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<shanty_tag::TagError> for ApiError {
|
||||
fn from(e: shanty_tag::TagError) -> Self {
|
||||
ApiError::Internal(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<shanty_org::OrgError> for ApiError {
|
||||
fn from(e: shanty_org::OrgError) -> Self {
|
||||
ApiError::Internal(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user