mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-28 10:29:30 +02:00
fix: name harmonization of endpoints & ingestion security hardening
This commit is contained in:
@@ -20,6 +20,9 @@ pub enum ApiError {
|
||||
|
||||
#[error("Unauthorized: {0}")]
|
||||
Unauthorized(String),
|
||||
|
||||
#[error("Payload too large: {0}")]
|
||||
PayloadTooLarge(String),
|
||||
}
|
||||
|
||||
impl From<AppError> for ApiError {
|
||||
@@ -67,6 +70,13 @@ impl IntoResponse for ApiError {
|
||||
status: "error".to_string(),
|
||||
},
|
||||
),
|
||||
Self::PayloadTooLarge(message) => (
|
||||
StatusCode::PAYLOAD_TOO_LARGE,
|
||||
ErrorResponse {
|
||||
error: message,
|
||||
status: "error".to_string(),
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
(status, Json(error_response)).into_response()
|
||||
@@ -132,6 +142,10 @@ mod tests {
|
||||
// Test unauthorized status
|
||||
let error = ApiError::Unauthorized("not allowed".to_string());
|
||||
assert_status_code(error, StatusCode::UNAUTHORIZED);
|
||||
|
||||
// Test payload too large status
|
||||
let error = ApiError::PayloadTooLarge("too big".to_string());
|
||||
assert_status_code(error, StatusCode::PAYLOAD_TOO_LARGE);
|
||||
}
|
||||
|
||||
// Alternative approach that doesn't try to parse the response body
|
||||
|
||||
Reference in New Issue
Block a user