mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor(errors): add parsing error types for context info (#911)
This commit is contained in:
@ -8,36 +8,23 @@
|
||||
///
|
||||
pub type CustomResult<T, E> = error_stack::Result<T, E>;
|
||||
|
||||
macro_rules! impl_error_display {
|
||||
($st: ident, $arg: tt) => {
|
||||
impl std::fmt::Display for $st {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fmt.write_str(&format!(
|
||||
"{{ error_type: {:?}, error_description: {} }}",
|
||||
self, $arg
|
||||
))
|
||||
}
|
||||
}
|
||||
};
|
||||
/// Parsing Errors
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ParsingError {
|
||||
///Failed to parse enum
|
||||
#[error("Failed to parse enum: {0}")]
|
||||
EnumParseFailure(&'static str),
|
||||
///Failed to parse struct
|
||||
#[error("Failed to parse struct: {0}")]
|
||||
StructParseFailure(&'static str),
|
||||
/// Failed to encode data to given format
|
||||
#[error("Failed to serialize to {0} format")]
|
||||
EncodeError(&'static str),
|
||||
/// Failed to parse data
|
||||
#[error("Unknown error while parsing")]
|
||||
UnknownError,
|
||||
}
|
||||
|
||||
macro_rules! impl_error_type {
|
||||
($name: ident, $arg: tt) => {
|
||||
#[doc = ""]
|
||||
#[doc = stringify!(Error variant $name)]
|
||||
#[doc = stringify!(Custom error variant for $arg)]
|
||||
#[doc = ""]
|
||||
#[derive(Debug)]
|
||||
pub struct $name;
|
||||
|
||||
impl_error_display!($name, $arg);
|
||||
|
||||
impl std::error::Error for $name {}
|
||||
};
|
||||
}
|
||||
|
||||
impl_error_type!(ParsingError, "Parsing error");
|
||||
|
||||
/// Validation errors.
|
||||
#[allow(missing_docs)] // Only to prevent warnings about struct fields not being documented
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
Reference in New Issue
Block a user