Skip to content

Commit

Permalink
refactor: update cubix
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Jan 4, 2025
1 parent 2362747 commit 7c7e22c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casdoor-rs-sdk"
version = "2.6.0"
version = "2.6.1"
edition = "2021"
license = "Apache-2.0"
description = "A Casdoor SDK (contain APIs) with more complete interfaces and better usability."
Expand All @@ -23,13 +23,13 @@ jsonwebtoken = "9.3.0"
urlencoding = "2.1"
oauth2 = "4.1"
toml = "0.8"
cubix = ">=0.8.2"
cubix = ">=0.10.0"
salvo = { version = ">=0.74", default-features = false, features = [
"oapi",
], optional = true }
casdoor-api = { package = "casdoor-sdk", version = "2.0.4", optional = true }

[features]
# default = ["api", "salvo"]
default = ["api", "salvo"]
salvo = ["dep:salvo", "cubix/salvo"]
api = ["dep:casdoor-api"]
18 changes: 10 additions & 8 deletions src/sdk/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{fmt::Display, sync::Once};

pub use cubix::api_response::ApiError;
use cubix::api_response::error_code::{ErrType, ModPath, ModSection};
pub use cubix::api_craft::{
errtype::{ErrPath, ErrPathParent, ErrPathRoot, ErrType},
respbody::ApiError,
};

use crate::StatusCode;

Expand Down Expand Up @@ -127,21 +129,21 @@ impl From<SdkError> for salvo::prelude::StatusError {
}
}

static mut MOD_PATH: ModPath = ModPath::default();
static mut ERR_PATH: ErrPath = ErrPath::default();

static INIT: Once = Once::new();

/// Initialize the suffix of the error code.
pub fn init_error_mod_path(mod1: ModSection, mod2: ModSection, mod3: ModSection) {
pub fn init_error_path(err_path: ErrPath) {
unsafe {
INIT.call_once(|| MOD_PATH = ModPath::new(mod1, mod2, mod3));
INIT.call_once(|| ERR_PATH = err_path);
}
}

pub const ERR_SDK_KEY: &str = "casdoor_sdk_err";

impl From<SdkError> for ApiError {
fn from(value: SdkError) -> Self {
ErrType::from(value.code)
.new_api_error(unsafe { MOD_PATH })
.with_detail(ERR_SDK_KEY, value.to_string())
(ErrType::from(value.code).api_error(&unsafe { ERR_PATH })).with_detail(ERR_SDK_KEY, value.to_string())
}
}
2 changes: 1 addition & 1 deletion src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod errors;
mod models;
use std::{ops::Deref, sync::Arc};

use cubix::MaybeString;
use cubix::api_craft::respbody::MaybeString;
pub use errors::*;
pub use models::*;
use serde::{
Expand Down

0 comments on commit 7c7e22c

Please sign in to comment.