Skip to content

Commit a154730

Browse files
authored
Merge pull request #36 from Ceng23333/dev/multi_model_0
feat: service支持多模型
2 parents 65a8a88 + 2d6b31f commit a154730

File tree

2 files changed

+225
-82
lines changed

2 files changed

+225
-82
lines changed

xtask/src/service/error.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use hyper::{Method, StatusCode};
1+
use hyper::{Method, StatusCode};
22
use serde::Serialize;
3+
use std::fmt;
34

45
#[derive(Debug)]
56
pub(crate) enum Error {
67
WrongJson(serde_json::Error),
78
NotFound(NotFoundError),
89
MsgNotSupported(MsgNotSupportedError),
10+
ModelNotFound(String),
911
}
1012

1113
#[derive(Serialize, Debug)]
@@ -39,6 +41,7 @@ impl Error {
3941
Self::WrongJson(..) => StatusCode::BAD_REQUEST,
4042
Self::NotFound(..) => StatusCode::NOT_FOUND,
4143
Self::MsgNotSupported(..) => StatusCode::BAD_REQUEST,
44+
Self::ModelNotFound(..) => StatusCode::NOT_FOUND,
4245
}
4346
}
4447

@@ -48,6 +51,20 @@ impl Error {
4851
Self::WrongJson(e) => e.to_string(),
4952
Self::NotFound(e) => serde_json::to_string(&e).unwrap(),
5053
Self::MsgNotSupported(e) => serde_json::to_string(&e).unwrap(),
54+
Self::ModelNotFound(model) => format!("Model not found: {}", model),
5155
}
5256
}
5357
}
58+
59+
impl fmt::Display for Error {
60+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61+
match self {
62+
Error::WrongJson(e) => write!(f, "Invalid JSON: {}", e),
63+
Error::NotFound(e) => write!(f, "Not Found: {} {}", e.method, e.uri),
64+
Error::MsgNotSupported(e) => write!(f, "Message type not supported: {:?}", e.message),
65+
Error::ModelNotFound(model) => write!(f, "Model not found: {}", model),
66+
}
67+
}
68+
}
69+
70+
impl std::error::Error for Error {}

0 commit comments

Comments
 (0)