feat: unified error type (#308)

* feat: unified error type

* fix: use type id to compare transport type
This commit is contained in:
4t145 2025-07-09 11:23:39 +08:00 • committed by GitHub
commit e615300fea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -63,9 +63,9 @@ pub enum RawContent {
pub type Content = Annotated<RawContent>;
impl RawContent {
pub fn json<S: Serialize>(json: S) -> Result<Self, crate::Error> {
pub fn json<S: Serialize>(json: S) -> Result<Self, crate::ErrorData> {
let json = serde_json::to_string(&json).map_err(|e| {
crate::Error::internal_error(
crate::ErrorData::internal_error(
"fail to serialize response to json",
Some(json!(
{"reason": e.to_string()}
@ -142,7 +142,7 @@ impl Content {
RawContent::embedded_text(uri, content).no_annotation()
}
pub fn json<S: Serialize>(json: S) -> Result<Self, crate::Error> {
pub fn json<S: Serialize>(json: S) -> Result<Self, crate::ErrorData> {
RawContent::json(json).map(|c| c.no_annotation())
}
}