1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Debug, Error, Serialize, Deserialize)]
pub enum Error {
#[error("json: {0}")]
Json(String),
#[error("worker: {0}")]
Worker(String),
#[error("expected object response")]
ExpectedObjectResponse,
#[error("expected object response")]
ExpectedObjectInitialized,
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error::Json(err.to_string())
}
}
impl From<worker::Error> for Error {
fn from(err: worker::Error) -> Self {
Error::Worker(err.to_string())
}
}
impl From<Error> for worker::Error {
fn from(err: Error) -> Self {
worker::Error::from(err.to_string())
}
}
#[derive(Debug, Error)]
pub enum CrateOrObjectError<ObjectError> {
Crate(#[from] Error),
Object(ObjectError),
}
impl<ObjectError: std::error::Error> From<CrateOrObjectError<ObjectError>> for worker::Error {
fn from(err: CrateOrObjectError<ObjectError>) -> Self {
match err {
CrateOrObjectError::Crate(err) => err.into(),
CrateOrObjectError::Object(err) => worker::Error::from(err.to_string()),
}
}
}