File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,19 +16,6 @@ pub struct ApiError {
1616 pub trace_id : Option < String > ,
1717}
1818
19- impl ApiError {
20- /// Creates a new API error.
21- pub fn new ( code : u32 , message : impl Into < String > ) -> Self {
22- Self {
23- code,
24- err_code : None ,
25- message : message. into ( ) ,
26- errors : None ,
27- trace_id : None ,
28- }
29- }
30- }
31-
3219impl < ' de > Deserialize < ' de > for ApiError {
3320 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
3421 where
Original file line number Diff line number Diff line change @@ -16,11 +16,21 @@ fn test_rate_limit() {
1616
1717#[ test]
1818fn test_api_error ( ) {
19- let error = ApiError :: new ( 429 , "Rate limited" ) ;
19+ let error: ApiError = serde_json:: from_value ( serde_json:: json!( {
20+ "code" : 429 ,
21+ "message" : "Rate limited"
22+ } ) )
23+ . unwrap ( ) ;
24+
2025 assert_eq ! ( error. err_code, None ) ;
2126 assert_eq ! ( error. code, 429 ) ;
27+ assert_eq ! ( error. message, "Rate limited" ) ;
2228
23- let auth_error = ApiError :: new ( 401 , "Unauthorized" ) ;
29+ let auth_error: ApiError = serde_json:: from_value ( serde_json:: json!( {
30+ "code" : 401 ,
31+ "message" : "Unauthorized"
32+ } ) )
33+ . unwrap ( ) ;
2434 assert_eq ! ( auth_error. code, 401 ) ;
2535}
2636
You can’t perform that action at this time.
0 commit comments