lingxia_platform/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum PlatformError {
6 #[error("Platform error: {0}")]
7 Platform(String),
8
9 #[error("Not supported: {0}")]
10 NotSupported(String),
11
12 #[error("Asset not found: {0}")]
13 AssetNotFound(String),
14
15 #[error("Invalid parameter: {0}")]
16 InvalidParameter(String),
17
18 #[error("Business error: code {0}")]
19 BusinessError(u32),
20
21 #[error("Callback dropped")]
22 CallbackDropped,
23
24 #[error("Page chrome presenter not mounted")]
27 PresenterUnavailable,
28}
29
30pub const PRESENTER_UNAVAILABLE_CODE: u32 = 1001;
34
35#[cfg(any(target_os = "android", target_env = "ohos"))]
39pub(crate) fn unmounted_presenter_or(error: PlatformError) -> PlatformError {
40 match error {
41 PlatformError::BusinessError(PRESENTER_UNAVAILABLE_CODE) => {
42 PlatformError::PresenterUnavailable
43 }
44 other => other,
45 }
46}
47
48pub type PlatformResult<T> = Result<T, PlatformError>;
50
51#[cfg(target_os = "android")]
52impl From<jni::errors::Error> for PlatformError {
53 fn from(value: jni::errors::Error) -> Self {
54 PlatformError::Platform(format!("JNI error: {}", value))
55 }
56}