CI / CI (push) Successful in 15m14s
All errors were API mismatches — handler code calling wrong method names, wrong argument types, or missing imports/derives. No logic changes. Build now passes with SQLX_OFFLINE=true. Key fixes: - embed_text -> embed_one, Vector -> Vec<f32> conversion - extract_token: extract auth header from HttpRequest first - AuthError variants aligned to actual enum definition - recursive async fns boxed (dfs_paths in inference + path_finder) - missing derives (Default, Serialize), imports (sqlx::Row, Timelike) - borrow-after-move: compute .len() before struct field move - streaming_body -> streaming with Result<Bytes> for SSE - CI: add SQLX_OFFLINE=true for offline builds without DB 25 files changed, 99 insertions(+), 81 deletions(-) Co-authored-by: rock <[email protected]>
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
/// Generic response builder for handlers
|
|
///
|
|
/// Reduces complexity by centralizing response formatting logic.
|
|
|
|
use actix_web::HttpResponse;
|
|
use serde_json::json;
|
|
|
|
/// Build a success response (200 OK)
|
|
pub fn success_response<T: serde::Serialize>(data: T) -> HttpResponse {
|
|
HttpResponse::Ok().json(data)
|
|
}
|
|
|
|
/// Build an error response (400 Bad Request)
|
|
pub fn bad_request(error: &str) -> HttpResponse {
|
|
HttpResponse::BadRequest().json(json!({ "error": error }))
|
|
}
|
|
|
|
/// Build a not found response (404 Not Found)
|
|
pub fn not_found(error: &str) -> HttpResponse {
|
|
HttpResponse::NotFound().json(json!({ "error": error }))
|
|
}
|
|
|
|
/// Build an internal server error response (500)
|
|
pub fn internal_error(error: &str) -> HttpResponse {
|
|
HttpResponse::InternalServerError().json(json!({ "error": error }))
|
|
}
|
|
|
|
/// Build an unauthorized response (401)
|
|
pub fn unauthorized(error: &str) -> HttpResponse {
|
|
HttpResponse::Unauthorized().json(json!({ "error": error }))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_success_response_builds() {
|
|
let resp = success_response(json!({"status": "ok"}));
|
|
assert_eq!(resp.status(), 200);
|
|
}
|
|
|
|
#[test]
|
|
fn test_bad_request_response_builds() {
|
|
let resp = bad_request("Invalid input");
|
|
assert_eq!(resp.status(), 400);
|
|
}
|
|
|
|
#[test]
|
|
fn test_not_found_response_builds() {
|
|
let resp = not_found("Not found");
|
|
assert_eq!(resp.status(), 404);
|
|
}
|
|
|
|
#[test]
|
|
fn test_internal_error_response_builds() {
|
|
let resp = internal_error("Server error");
|
|
assert_eq!(resp.status(), 500);
|
|
}
|
|
}
|