File tree Expand file tree Collapse file tree 2 files changed +31
-10
lines changed Expand file tree Collapse file tree 2 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -79,18 +79,34 @@ impl<Http: HttpClient> Client<Http> {
7979 & self ,
8080 value : & Value ,
8181 ) -> Result < IndexesResults < Http > , Error > {
82- let raw_indexes = value[ "results" ] . as_array ( ) . unwrap ( ) ;
83-
82+ let raw_indexes = value[ "results" ]
83+ . as_array ( )
84+ . ok_or_else ( || Error :: ParseStringError ( "Missing or invalid 'results' field" . to_string ( ) ) ) ?;
85+
86+ let limit = value[ "limit" ]
87+ . as_u64 ( )
88+ . ok_or_else ( || Error :: ParseStringError ( "Missing or invalid 'limit' field" . to_string ( ) ) ) ? as u32 ;
89+
90+ let offset = value[ "offset" ]
91+ . as_u64 ( )
92+ . ok_or_else ( || Error :: ParseStringError ( "Missing or invalid 'offset' field" . to_string ( ) ) ) ? as u32 ;
93+
94+ let total = value[ "total" ]
95+ . as_u64 ( )
96+ . ok_or_else ( || Error :: ParseStringError ( "Missing or invalid 'total' field" . to_string ( ) ) ) ? as u32 ;
97+
98+ let results = raw_indexes
99+ . iter ( )
100+ . map ( |raw_index| Index :: from_value ( raw_index. clone ( ) , self . clone ( ) ) )
101+ . collect :: < Result < _ , _ > > ( ) ?;
102+
84103 let indexes_results = IndexesResults {
85- limit : value[ "limit" ] . as_u64 ( ) . unwrap ( ) as u32 ,
86- offset : value[ "offset" ] . as_u64 ( ) . unwrap ( ) as u32 ,
87- total : value[ "total" ] . as_u64 ( ) . unwrap ( ) as u32 ,
88- results : raw_indexes
89- . iter ( )
90- . map ( |raw_index| Index :: from_value ( raw_index. clone ( ) , self . clone ( ) ) )
91- . collect :: < Result < _ , _ > > ( ) ?,
104+ limit,
105+ offset,
106+ total,
107+ results,
92108 } ;
93-
109+
94110 Ok ( indexes_results)
95111 }
96112
Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ pub enum Error {
1717 /// The Meilisearch server returned an invalid JSON for a request.
1818 #[ error( "Error parsing response JSON: {}" , . 0 ) ]
1919 ParseError ( #[ from] serde_json:: Error ) ,
20+
21+ /// An error occurred while parsing the fields of the response JSON.
22+ #[ error( "Error parsing fields: {0}" ) ]
23+ ParseStringError ( String ) ,
24+
2025 /// A timeout happened while waiting for an update to complete.
2126 #[ error( "A task did not succeed in time." ) ]
2227 Timeout ,
You can’t perform that action at this time.
0 commit comments