Major architectural shift from Next.js to a lightweight Vite + React SPA model ("Puppet Architecture") to better support real-time workflow visualization and strict type safety.
Key Changes:
1. **Architecture & Build**:
- Initialized Vite + React + TypeScript project.
- Configured Tailwind CSS v4 and Shadcn UI.
- Archived legacy Next.js frontend to 'frontend/archive/v2_nextjs'.
2. **Core Features**:
- **Dashboard**: Implemented startup page with Symbol, Market, and Template selection.
- **Report Page**:
- **Workflow Visualization**: Integrated ReactFlow to show dynamic DAG of analysis tasks.
- **Real-time Status**: Implemented Mock SSE logic to simulate task progress, logs, and status changes.
- **Multi-Tab Interface**: Dynamic tabs for 'Overview', 'Fundamental Data', and analysis modules.
- **Streaming Markdown**: Enabled typewriter-style streaming rendering for analysis reports using 'react-markdown'.
- **Config Page**: Implemented settings for AI Providers, Data Sources, and Templates using TanStack Query.
3. **Documentation**:
- Created v2.0 User Guide ('docs/1_requirements/20251122_[Active]_user-guide_v2.md').
- Implemented 'DocsPage' in frontend to render the user guide directly within the app.
4. **Backend Alignment**:
- Created 'docs/frontend/backend_todos.md' outlining necessary backend adaptations (OpenAPI, Progress tracking).
This commit establishes the full frontend 'shell' ready for backend integration.
63 lines
2.3 KiB
Rust
63 lines
2.3 KiB
Rust
use axum::{Json, http::StatusCode, response::IntoResponse};
|
|
use serde_json::json;
|
|
use thiserror::Error;
|
|
|
|
pub type Result<T> = std::result::Result<T, AppError>;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AppError {
|
|
#[error("Configuration error: {0}")]
|
|
Configuration(String),
|
|
|
|
#[error("Message bus error: {0}")]
|
|
MessageBus(#[from] async_nats::Error),
|
|
|
|
#[error("Message bus publish error: {0}")]
|
|
MessageBusPublish(#[from] async_nats::PublishError),
|
|
|
|
#[error("Message bus subscribe error: {0}")]
|
|
MessageBusSubscribe(String),
|
|
|
|
#[error("Message bus connect error: {0}")]
|
|
MessageBusConnect(String),
|
|
|
|
#[error("HTTP request to another service failed: {0}")]
|
|
ServiceRequest(#[from] reqwest::Error),
|
|
|
|
#[error("Bad request: {0}")]
|
|
BadRequest(String),
|
|
|
|
#[error("Internal error: {0}")]
|
|
Internal(#[from] anyhow::Error),
|
|
}
|
|
|
|
impl IntoResponse for AppError {
|
|
fn into_response(self) -> axum::response::Response {
|
|
let (status, message) = match &self {
|
|
AppError::Configuration(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg.clone()),
|
|
AppError::MessageBus(err) => (StatusCode::SERVICE_UNAVAILABLE, err.to_string()),
|
|
AppError::MessageBusPublish(err) => (StatusCode::SERVICE_UNAVAILABLE, err.to_string()),
|
|
AppError::MessageBusSubscribe(msg) => (StatusCode::SERVICE_UNAVAILABLE, msg.clone()),
|
|
AppError::MessageBusConnect(msg) => (StatusCode::SERVICE_UNAVAILABLE, msg.clone()),
|
|
AppError::ServiceRequest(err) => (StatusCode::BAD_GATEWAY, err.to_string()),
|
|
AppError::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg.clone()),
|
|
AppError::Internal(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()),
|
|
};
|
|
let body = Json(json!({ "error": message }));
|
|
(status, body).into_response()
|
|
}
|
|
}
|
|
|
|
// 手动实现针对 async-nats 泛型错误类型的 From 转换
|
|
impl From<async_nats::error::Error<async_nats::ConnectErrorKind>> for AppError {
|
|
fn from(err: async_nats::error::Error<async_nats::ConnectErrorKind>) -> Self {
|
|
AppError::MessageBusConnect(err.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<async_nats::SubscribeError> for AppError {
|
|
fn from(err: async_nats::SubscribeError) -> Self {
|
|
AppError::MessageBusSubscribe(err.to_string())
|
|
}
|
|
}
|