google_maps/distance_matrix/
error.rs1#[derive(Clone, Debug, thiserror::Error, miette::Diagnostic)]
7pub enum Error {
8 #[error("`with_arrival_time` method may only be used when \
16 `with_travel_mode` is set to `TravelMode::Transit`. The travel mode has
17 been set to `{0}` and the arrival time has been set to `{1}`")]
18 #[diagnostic(
19 code(google_maps::distance_matrix::validate::arrival_time_is_for_transit_only),
20 url(docsrs),
21 help("try again either with a travel mode of `TravelMode::Transit` or \
22 no arrival time")
23 )]
24 ArrivalTimeIsForTransitOnly(String, String),
25
26 #[error("`with_departure_time` method cannot be used when \
28 `with_arrival_time` has been set. The arrival time has been set to \
29 `{0}` and the departure time has been set to `{1}`")]
30 #[diagnostic(
31 code(google_maps::distance_matrix::validate::either_departure_time_or_arrival_time),
32 url(docsrs),
33 help("try again either with no arrival time or no departure time")
34 )]
35 EitherDepartureTimeOrArrivalTime(String, String),
36
37 #[error("`with_transit_modes` method may only be used when \
39 `with_travel_mode` is set to `TravelMode::Transit`. The travel mode \
40 has been set to `{0}` and the transit modes have been set to `{1}`")]
41 #[diagnostic(
42 code(google_maps::distance_matrix::validate::transit_mode_is_for_transit_only),
43 url(docsrs),
44 help("try again either with a travel mode of `TravelMode::Transit` or no transit modes")
45 )]
46 TransitModeIsForTransitOnly(String, String),
47
48 #[error("`with_transit_route_preference` method may only be used when \
50 `with_travel_mode` is set to `TravelMode::Transit`. The travel mode \
51 has been set to `{0}` and the transit route preference has been set to \
52 `{1}`")]
53 #[diagnostic(
54 code(google_maps::distance_matrix::validate::transit_mode_is_for_transit_only),
55 url(docsrs),
56 help("try again either with a travel mode of `TravelMode::Transit` or no transit route preference")
57 )]
58 TransitRoutePreferenceIsForTransitOnly(String, String),
59
60 #[error("invalid element status: `{0}`")]
67 #[diagnostic(
68 code(google_maps::distance_matrix::parse::invalid_element_status_code),
69 url("https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#DistanceMatrixStatus"),
70 help("valid codes are `OK`, `NOT_FOUND`, `ZERO_RESULTS`, and \
71 `MAX_ROUTE_LENGTH_EXCEEDED`")
72 )]
73 InvalidElementStatusCode(String),
74
75 #[error("invalid status: `{0}`")]
81 #[diagnostic(
82 code(google_maps::distance_matrix::parse::invalid_status_code),
83 url("https://developers.google.com/maps/documentation/directions/get-directions#DirectionsStatus"),
84 help("valid codes are `INVALID_REQUEST`, `MAX_ELEMENTS_EXCEEDED`, \
85 `MAX_DIMENSIONS_EXCEEDED`, `OVER_QUERY_LIMIT`, `OVER_QUERY_LIMIT`, \
86 `REQUEST_DENIED`, and `UNKNOWN_ERROR`")
87 )]
88 InvalidStatusCode(String),
89
90 #[error("invalid request")]
97 #[diagnostic(
98 code(google_maps::distance_matrix::status::invalid_request),
99 url("https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#DistanceMatrixStatus"),
100 help("indicates that the provided request was invalid. Common causes \
101 of this status include an invalid parameter or parameter value")
102 )]
103 InvalidRequest,
104
105 #[error("maximum elements exceeded")]
108 #[diagnostic(
109 code(google_maps::distance_matrix::status::max_elements_exceeded),
110 url("https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#DistanceMatrixStatus"),
111 help("indicates that the product of origins and destinations exceeds \
112 the per-query limit")
113 )]
114 MaxElementsExceeded,
115
116 #[error("maximum dimensions exceeded")]
119 #[diagnostic(
120 code(google_maps::distance_matrix::status::max_dimensions_exceeded),
121 url("https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#DistanceMatrixStatus"),
122 help("indicates that the number of origins or destinations exceeds the \
123 per-query limit")
124 )]
125 MaxDimensionsExceeded,
126
127 #[error("over daily limit")]
151 #[diagnostic(
152 code(google_maps::distance_matrix::status::over_daily_limit),
153 url("https://developers.google.com/maps/faq#over-limit-key-error"),
154 help("either the API key is missing or invalid, billing has not been \
155 enabled on your account, a self-imposed usage cap has been \
156 exceeded, or the provided method of payment is no longer valid \
157 (for example, a credit card has expired)")
158 )]
159 OverDailyLimit,
160
161 #[error("over query limit")]
176 #[diagnostic(
177 code(google_maps::distance_matrix::status::over_query_limit),
178 url("https://developers.google.com/maps/faq#over-limit-key-error"),
179 help("either you have exceeded the QPS limits, billing has not been \
180 enabled on your account, a self-imposed usage cap has been \
181 exceeded or the provided method of payment is no longer valid")
182 )]
183 OverQueryLimit,
184
185 #[error("request denied")]
187 #[diagnostic(
188 code(google_maps::distance_matrix::status::request_denied),
189 url("https://developers.google.com/maps/documentation/directions/get-directions#DirectionsStatus"),
190 help("indicates that the service denied use of the Distance Matrix \
191 service by your application")
192 )]
193 RequestDenied,
194
195 #[error("unknown error")]
197 #[diagnostic(
198 code(google_maps::distance_matrix::status::unknown_error),
199 url("https://developers.google.com/maps/documentation/distance-matrix/distance-matrix#DistanceMatrixStatus"),
200 help("indicates a Distance Matrix request could not be processed due \
201 to a server error. The request may succeed if you try again.")
202 )]
203 UnknownError,
204} use crate::ClassifiedError;
209
210impl crate::traits::ClassifiableError<'_, Self> for Error {
211 fn classify(&self) -> ClassifiedError<'_, Self> {
216 match self {
217 Self::UnknownError => ClassifiedError::Transient(self),
218 _ => ClassifiedError::Permanent(self),
219 } } }