Skip to content

Commit 0f48bb1

Browse files
author
Guantong
committed
Impl Display for Error
1 parent bcefc1a commit 0f48bb1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![warn(unused_crate_dependencies)]
22

33
pub mod apis;
4+
use std::fmt::{Display, Formatter, self};
5+
46
pub use apis::*;
57
pub mod openai;
68
pub use openai::*;
@@ -20,3 +22,12 @@ pub enum Error {
2022
/// An Error not related to the API
2123
RequestError(String),
2224
}
25+
26+
impl Display for Error {
27+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28+
match self {
29+
Error::ApiError(msg) => write!(f, "API error: {}", msg),
30+
Error::RequestError(msg) => write!(f, "Request error: {}", msg),
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)