feat: properly handle RPC errors
							parent
							
								
									7efa42f1e5
								
							
						
					
					
						commit
						e4ccbddb0c
					
				
							
								
								
									
										13
									
								
								client.v
								
								
								
								
							
							
						
						
									
										13
									
								
								client.v
								
								
								
								
							|  | @ -24,9 +24,10 @@ pub fn new_with_url(url string) &Client { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct SuccessResponse { | struct Response { | ||||||
| 	result_count int       [json: resultCount] | 	@type   string    [json: 'type'] | ||||||
| 	results      []Package | 	error   string | ||||||
|  | 	results []Package | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn (c Client) request(params map[string][]string) ?[]Package { | fn (c Client) request(params map[string][]string) ?[]Package { | ||||||
|  | @ -45,7 +46,11 @@ fn (c Client) request(params map[string][]string) ?[]Package { | ||||||
| 		return error('error') | 		return error('error') | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	data := json.decode(SuccessResponse, res.body)? | 	data := json.decode(Response, res.body)? | ||||||
|  | 
 | ||||||
|  | 	if data.@type == 'error' { | ||||||
|  | 		return error('Server responded with an error: $data.error') | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	return data.results | 	return data.results | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue