Skip to content

Commit d0d63a0

Browse files
committed
fix all_applications
1 parent af4d038 commit d0d63a0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

fplus-http-server/src/router/application.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ pub async fn all_applications() -> impl Responder {
122122
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to serialize applications: {}", e)),
123123
}
124124
},
125-
Err(e) => HttpResponse::BadRequest().body(e.to_string()),
125+
Err(errors) => {
126+
match serde_json::to_string_pretty(&errors) {
127+
Ok(json) => HttpResponse::BadRequest().content_type("application/json").body(json),
128+
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to serialize errors: {}", e)),
129+
}
130+
},
126131
}
127132
}
128133

fplus-lib/src/core/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,10 @@ impl LDNApplication {
239239
}
240240

241241
pub async fn all_applications() -> Result<Vec<(ApplicationFile, String, String)>, Vec<LDNError>> {
242-
let allocators = database::get_allocators().await.map_err(|_| LDNError::New("Failed to get allocators from the database"))?;
243-
let mut all_apps: Vec<(ApplicationFile, String, String)> = Vec::new();
242+
let allocators = match database::get_allocators().await {
243+
Ok(allocs) => allocs,
244+
Err(e) => return Err(vec![LDNError::Load(format!("Failed to retrieve allocators: {}", e))]),
245+
}; let mut all_apps: Vec<(ApplicationFile, String, String)> = Vec::new();
244246
let mut errors: Vec<LDNError> = Vec::new();
245247

246248
for allocator in allocators {

fplus-lib/src/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use actix_web::{
88
body::{BodySize, MessageBody},
99
web::Bytes,
1010
};
11+
use serde::{Deserialize, Serialize};
1112

12-
#[derive(Debug)]
13+
#[derive(Debug, Serialize, Deserialize)]
1314
pub enum LDNError {
1415
New(String),
1516
Load(String),

0 commit comments

Comments
 (0)