chore: Refactor process_tauri_request function for improved readability and error handling

This commit is contained in:
Florian Briand 2024-07-24 23:39:27 +02:00
parent d33140ebaf
commit f8d7f82c50
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B

View File

@ -1,4 +1,3 @@
use core::panic;
use std::sync::Arc; use std::sync::Arc;
use tauri::{path::BaseDirectory, Manager}; use tauri::{path::BaseDirectory, Manager};
@ -24,23 +23,18 @@ async fn process_tauri_request(
let request = AxumRequest::from_parts(parts, body); let request = AxumRequest::from_parts(parts, body);
// Process the request with the router // Process the request with the router
let response = match router.as_service().ready().await { let response = router
Ok(ready_service) => ready_service.call(request).await, .as_service()
Err(_error) => panic!("Failed to get ready service"), .ready().await
}; .expect("Failed to get ready service")
.call(request).await
let response = match response { .expect("Failed to get response from router");
Ok(response) => response,
Err(_error) => panic!("Problem getting response from request."),
};
// Convert the Axum response to a Tauri response // Convert the Axum response to a Tauri response
let (parts, body) = response.into_parts(); let (parts, body) = response.into_parts();
let body = to_bytes(body, usize::MAX).await { let body = to_bytes(body, usize::MAX).await
Ok(bytes) => bytes.to_vec(), .expect("Failed to convert body to bytes")
Err(_error) => panic!("Problem converting response body to bytes."), .to_vec();
};
let response = TauriResponse::from_parts(parts, body); let response = TauriResponse::from_parts(parts, body);
response response