@@ -56,6 +56,18 @@ pub enum IndexeddbSerializerError {
56
56
CryptoStoreError ( #[ from] CryptoStoreError ) ,
57
57
}
58
58
59
+ impl From < web_sys:: DomException > for IndexeddbSerializerError {
60
+ fn from ( frm : web_sys:: DomException ) -> Self {
61
+ Self :: DomException { name : frm. name ( ) , message : frm. message ( ) , code : frm. code ( ) }
62
+ }
63
+ }
64
+
65
+ impl From < serde_wasm_bindgen:: Error > for IndexeddbSerializerError {
66
+ fn from ( e : serde_wasm_bindgen:: Error ) -> Self {
67
+ Self :: Serialization ( serde:: de:: Error :: custom ( e. to_string ( ) ) )
68
+ }
69
+ }
70
+
59
71
#[ derive( Debug , Deserialize , Serialize ) ]
60
72
#[ serde( untagged) ]
61
73
pub enum MaybeEncrypted {
@@ -107,15 +119,15 @@ impl IndexeddbSerializer {
107
119
& self ,
108
120
table_name : & str ,
109
121
key : T ,
110
- ) -> Result < IdbKeyRange , IndexeddbCryptoStoreError >
122
+ ) -> Result < IdbKeyRange , IndexeddbSerializerError >
111
123
where
112
124
T : SafeEncode ,
113
125
{
114
126
match & self . store_cipher {
115
127
Some ( cipher) => key. encode_to_range_secure ( table_name, cipher) ,
116
128
None => key. encode_to_range ( ) ,
117
129
}
118
- . map_err ( |e| IndexeddbCryptoStoreError :: DomException {
130
+ . map_err ( |e| IndexeddbSerializerError :: DomException {
119
131
code : 0 ,
120
132
name : "IdbKeyRangeMakeError" . to_owned ( ) ,
121
133
message : e,
@@ -130,7 +142,7 @@ impl IndexeddbSerializer {
130
142
pub fn serialize_value (
131
143
& self ,
132
144
value : & impl Serialize ,
133
- ) -> Result < JsValue , IndexeddbCryptoStoreError > {
145
+ ) -> Result < JsValue , IndexeddbSerializerError > {
134
146
let serialized = self . maybe_encrypt_value ( value) ?;
135
147
Ok ( serde_wasm_bindgen:: to_value ( & serialized) ?)
136
148
}
@@ -184,7 +196,7 @@ impl IndexeddbSerializer {
184
196
pub fn deserialize_value < T : DeserializeOwned > (
185
197
& self ,
186
198
value : JsValue ,
187
- ) -> Result < T , IndexeddbCryptoStoreError > {
199
+ ) -> Result < T , IndexeddbSerializerError > {
188
200
// Objects which are serialized nowadays should be represented as a
189
201
// `MaybeEncrypted`. However, `serialize_value` previously used a
190
202
// different format, so we need to handle that in case we have old data.
@@ -238,11 +250,11 @@ impl IndexeddbSerializer {
238
250
pub fn deserialize_legacy_value < T : DeserializeOwned > (
239
251
& self ,
240
252
value : JsValue ,
241
- ) -> Result < T , IndexeddbCryptoStoreError > {
253
+ ) -> Result < T , IndexeddbSerializerError > {
242
254
match & self . store_cipher {
243
255
Some ( cipher) => {
244
256
if !value. is_array ( ) {
245
- return Err ( IndexeddbCryptoStoreError :: CryptoStoreError (
257
+ return Err ( IndexeddbSerializerError :: CryptoStoreError (
246
258
CryptoStoreError :: UnpicklingError ,
247
259
) ) ;
248
260
}
0 commit comments