Make client error serializable ()

This commit is contained in:
hchockarprasad 2023-05-23 01:32:48 +05:30 committed by GitHub
parent cdf97fcb96
commit 53d8e9c628
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions
lib/src
src/err

View file

@ -4,6 +4,7 @@ use crate::sql::Edges;
use crate::sql::Object;
use crate::sql::Thing;
use crate::sql::Value;
use serde::Serialize;
use std::io;
use std::path::PathBuf;
use thiserror::Error;
@ -200,3 +201,12 @@ impl From<pharos::PharErr> for crate::Error {
Self::Api(Error::Ws(error.to_string()))
}
}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.to_string().as_str())
}
}

View file

@ -157,7 +157,7 @@ pub mod error {
}
/// An error originating from the SurrealDB client library
#[derive(thiserror::Error, Debug)]
#[derive(Debug, thiserror::Error, serde::Serialize)]
pub enum Error {
/// An error with an embedded storage engine
#[error("{0}")]

View file

@ -1,6 +1,7 @@
use base64::DecodeError as Base64Error;
use jsonwebtoken::errors::Error as JWTError;
use reqwest::Error as ReqwestError;
use serde::Serialize;
use serde_cbor::error::Error as CborError;
use serde_json::error::Error as JsonError;
use serde_pack::encode::Error as PackError;
@ -82,3 +83,12 @@ impl From<surrealdb::error::Db> for Error {
Error::Db(error.into())
}
}
impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.to_string().as_str())
}
}