v0.1.3-rc.2

This commit is contained in:
wisdgod
2024-12-31 23:20:09 +08:00
parent 5505ccc6cb
commit d1a246a5a7
36 changed files with 2294 additions and 1444 deletions

View File

@@ -1,4 +1,4 @@
use crate::aiserver::v1::throw_error_check_request::Error as ErrorType;
use super::aiserver::v1::throw_error_check_request::Error as ErrorType;
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
@@ -31,9 +31,9 @@ pub struct ErrorDebug {
}
impl ErrorDebug {
pub fn is_valid(&self) -> bool {
ErrorType::from_str_name(&self.error).is_some()
}
// pub fn is_valid(&self) -> bool {
// ErrorType::from_str_name(&self.error).is_some()
// }
pub fn status_code(&self) -> u16 {
match ErrorType::from_str_name(&self.error) {
@@ -83,6 +83,8 @@ pub struct ErrorDetails {
pub is_retryable: bool,
}
use crate::common::models::{ApiStatus, ErrorResponse as CommonErrorResponse};
impl ChatError {
pub fn to_json(&self) -> serde_json::Value {
serde_json::to_value(self).unwrap()
@@ -135,6 +137,15 @@ impl ErrorResponse {
pub fn native_code(&self) -> String {
self.code.replace("_", " ").to_lowercase()
}
pub fn to_common(self) -> CommonErrorResponse {
CommonErrorResponse {
status: ApiStatus::Error,
code: Some(self.status),
error: self.error.as_ref().map(|error| error.message.clone()).or(Some(self.code.clone())),
message: self.error.as_ref().map(|error| error.details.clone()),
}
}
}
pub enum StreamError {