1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Roads API error types and error messages.
// -----------------------------------------------------------------------------
//
/// An error produced by a Google Maps Roads API request.
#[derive(Clone, Debug, thiserror::Error, miette::Diagnostic)]
pub enum Error {
// -------------------------------------------------------------------------
// Client-side errors:
// -------------------------------------------------------------------------
// Parsing errors:
/// Invalid status code.
///
/// Valid codes are `INVALID_ARGUMENT`, `PERMISSION_DENIED`, `NOT_FOUND` and
/// `RESOURCE_EXHAUSTED`
#[error("invalid status: `{0}`")]
#[diagnostic(
code(google_maps::roads::parse::invalid_status_code),
url("https://developers.google.com/maps/documentation/roads/errors#errors"),
help("valid codes are `INVALID_ARGUMENT`, `PERMISSION_DENIED`, \
`NOT_FOUND` and `RESOURCE_EXHAUSTED`")
)]
InvalidStatusCode(String),
// -------------------------------------------------------------------------
// Server-side errors (statuses):
// -------------------------------------------------------------------------
/// Invalid argument.
///
/// 1. Your API key is not valid or was not included in the request. Please
/// ensure that you've included the entire key, and that you've enabled
/// the API for this key.
///
/// 2. Your request contained invalid arguments. The most likely causes of
/// this error are:
///
/// * A problem with your path parameter.
///
/// * Please ensure you have at least 1, and fewer than 100 points. Each
/// point should be a pair of numbers separated by a comma, such as:
/// `48.409114,-123.369158`. Points should be separated by a pipe:
/// `|`.
///
/// * Your request included an invalid `placeId`.
///
/// * Your request included both `placeId`s and a `path`. Only one of
/// these parameters may be specified for each request. This error
/// will not be returned if a `placeId` is passed for a road which no
/// longer exists, or for a place which is not a road.
#[error("invalid argument: {0}")]
#[diagnostic(
code(google_maps::roads::status::invalid_argument),
url("https://developers.google.com/maps/documentation/roads/errors#errors"),
help("your API key is not valid or was not included in the request or \
your request contained invalid arguments")
)]
InvalidArgument(String),
/// Permission denied indicates that the request was denied for one or more
/// of the following reasons:
///
/// * The API key is missing or invalid.
///
/// * Billing has not been enabled on your account.
///
/// * A self-imposed usage cap has been exceeded.
///
/// * The provided method of payment is no longer valid (for example, a
/// credit card has expired).
///
/// In order to use Google Maps Platform products, billing must be enabled
/// on your account, and all requests must include a valid API key. To fix
/// this, take the following steps:
///
/// * [Get an API key](https://developers.google.com/maps/documentation/roads/errors?hl=en#new-key)
///
/// * [Enable billing](https://console.cloud.google.com/project/_/billing/enable)
/// on your account.
///
/// * [Adjust your usage cap](https://developers.google.com/maps/documentation/roads/errors?hl=en#usage-cap)
/// to increase your daily limit (if applicable).
#[error("permission denied: {0}")]
#[diagnostic(
code(google_maps::roads::status::permission_denied),
url("https://developers.google.com/maps/documentation/roads/errors#errors"),
help("either the API key is missing or invalid, billing has not been \
enabled on your account, a self-imposed usage cap has been \
exceeded, or the provided method of payment is no longer valid \
(for example, a credit card has expired)")
)]
PermissionDenied(String),
/// Not found. Ensure that you are sending requests to
/// `https://roads.googleapis.com/` and not `http://roads.googleapis.com/`.
#[error("not found: {0}")]
#[diagnostic(
code(google_maps::roads::status::not_found),
url("https://developers.google.com/maps/documentation/roads/errors#errors"),
help("ensure that you are sending requests to \
`https://roads.googleapis.com/` and not \
`http://roads.googleapis.com/`")
)]
NotFound(String),
/// Resource exhaused. You have exceeded the request limit that you
/// configured in the Google Cloud Platform Console. This limit is typically
/// set as requests per day, requests per 100 seconds, and requests per 100
/// seconds per user. This limit should be configured to prevent a single or
/// small group of users from exhausting your daily quota, while still
/// allowing reasonable access to all users. See Capping API Usage to
/// configure these limits.
#[error("resource exhausted: {0}")]
#[diagnostic(
code(google_maps::roads::status::permission_denied),
url("https://cloud.google.com/apis/docs/capping-api-usage"),
help("you have exceeded the request limit that you configured in the \
Google Cloud Platform Console")
)]
ResourceExhausted(String),
} // enum Error
// -----------------------------------------------------------------------------
use crate::ClassifiedError;
impl crate::traits::ClassifiableError<'_, Self> for Error {
/// Classifies an API error as a `Transient` error or `Permanent` error.
///
/// This classification will, in turn, be used to decide whether the HTTP
/// request should be retried or not.
fn classify(&self) -> ClassifiedError<'_, Self> {
ClassifiedError::Permanent(self)
} // fn
} // impl