Skip to main content

rusty_ssr/
error.rs

1//! Error types for Rusty SSR
2
3use std::fmt;
4
5/// Result type alias for SSR operations
6pub type SsrResult<T> = Result<T, SsrError>;
7
8/// Errors that can occur during SSR operations
9#[derive(Debug)]
10pub enum SsrError {
11    /// Failed to load the JavaScript bundle
12    BundleLoad(String),
13
14    /// V8 runtime initialization failed
15    V8Init(String),
16
17    /// JavaScript execution error
18    JsExecution(String),
19
20    /// Render timeout
21    Timeout,
22
23    /// Cache error
24    Cache(String),
25
26    /// Pool is full, request was rejected
27    PoolFull,
28
29    /// Configuration error
30    Config(String),
31
32    /// HTML template error
33    Template(String),
34
35    /// IO error
36    Io(std::io::Error),
37}
38
39impl fmt::Display for SsrError {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            SsrError::BundleLoad(msg) => write!(f, "Bundle load error: {}", msg),
43            SsrError::V8Init(msg) => write!(f, "V8 initialization error: {}", msg),
44            SsrError::JsExecution(msg) => write!(f, "JavaScript execution error: {}", msg),
45            SsrError::Timeout => write!(f, "Render timeout"),
46            SsrError::Cache(msg) => write!(f, "Cache error: {}", msg),
47            SsrError::PoolFull => write!(f, "V8 pool is full, request rejected"),
48            SsrError::Template(msg) => write!(f, "Template error: {}", msg),
49            SsrError::Config(msg) => write!(f, "Configuration error: {}", msg),
50            SsrError::Io(err) => write!(f, "IO error: {}", err),
51        }
52    }
53}
54
55impl std::error::Error for SsrError {
56    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
57        match self {
58            SsrError::Io(err) => Some(err),
59            _ => None,
60        }
61    }
62}
63
64impl From<std::io::Error> for SsrError {
65    fn from(err: std::io::Error) -> Self {
66        SsrError::Io(err)
67    }
68}