ohos_web_binding/
error.rs1#[derive(Debug, Clone)]
2pub enum ArkWebError {
3 WebviewCreateFailed(String),
4 ArkWebApiMemberMissing(String),
5 EvaluateScriptCallbackAlreadyExists,
6 JsApiRegisterFailed(String),
7}
8
9impl std::fmt::Display for ArkWebError {
10 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11 match self {
12 ArkWebError::WebviewCreateFailed(web_tag) => {
13 write!(f, "Webview create failed: {}", web_tag)
14 }
15 ArkWebError::ArkWebApiMemberMissing(member) => {
16 write!(f, "ArkWeb API member missing: {}", member)
17 }
18 ArkWebError::EvaluateScriptCallbackAlreadyExists => {
19 write!(f, "Evaluate script callback already exists")
20 }
21 ArkWebError::JsApiRegisterFailed(obj_name) => {
22 write!(f, "JS API register failed: {}", obj_name)
23 }
24 }
25 }
26}
27
28impl std::error::Error for ArkWebError {}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum HttpBodyStreamError {
33 NullStream,
34 SetUserDataFailed(i32),
35 SetReadCallbackFailed(i32),
36 NotInitialized,
37 InitializationFailed(i32),
38 InvalidReadSize(usize),
39 ReadFailed(i32),
40 InvalidReadCount { count: i32, capacity: usize },
41 UnexpectedBuffer,
42 NoProgress,
43}
44
45impl std::fmt::Display for HttpBodyStreamError {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 match self {
48 Self::NullStream => f.write_str("HTTP body stream is null"),
49 Self::SetUserDataFailed(code) => {
50 write!(f, "Failed to register body stream state: {code}")
51 }
52 Self::SetReadCallbackFailed(code) => {
53 write!(f, "Failed to register body read callback: {code}")
54 }
55 Self::NotInitialized => f.write_str("HTTP body stream has not been initialized"),
56 Self::InitializationFailed(code) => write!(f, "Body initialization failed: {code}"),
57 Self::InvalidReadSize(size) => write!(f, "Body read size exceeds i32::MAX: {size}"),
58 Self::ReadFailed(code) => write!(f, "Body read failed: {code}"),
59 Self::InvalidReadCount { count, capacity } => write!(
60 f,
61 "Body read returned {count} bytes for a {capacity}-byte buffer"
62 ),
63 Self::UnexpectedBuffer => f.write_str("Body read returned an unexpected buffer"),
64 Self::NoProgress => f.write_str("Body stream stopped before EOF"),
65 }
66 }
67}
68
69impl std::error::Error for HttpBodyStreamError {}