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
/// Why a request could not be built or a response could not be used.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
#[cfg_attr(feature = "uniffi", derive(uniffi::Error))]
#[cfg_attr(feature = "uniffi", uniffi::export(Display))]
// `Error` is JavaScript's own type for errors.
#[cfg_attr(
feature = "unstable-wasm",
derive(serde::Serialize, tsify::Tsify),
serde(tag = "type", rename_all = "camelCase"),
tsify(rename = "Failure")
)]
pub enum Error {
/// The [`Network`](crate::Network) lacks something the request needs,
/// such as a time zone, or its description cannot be read.
#[error("the network is not usable: {message}")]
InvalidNetwork {
/// What is missing or wrong.
message: String,
},
/// The query holds a value no request of the protocol can carry, such as
/// a time outside the supported range.
#[error("the query is invalid: {message}")]
InvalidQuery {
/// What is wrong.
message: String,
},
/// The network's server is known not to answer this kind of request,
/// see [`Network::unsupported`](crate::Network::unsupported), or the
/// network lacks what the request needs: an `OpenTripPlanner` network
/// without a [`Network::geocoder`](crate::Network::geocoder) cannot
/// search for locations.
#[error("not supported: {message}")]
Unsupported {
/// What is not supported.
message: String,
},
/// The network does not know the stop the query names, or cannot plan
/// a trip from or to a place because it knows no stop near it.
#[error("not found: {message}")]
NotFound {
/// What the server said, or what was missing in its answer.
message: String,
},
/// The server redirected the request, so the endpoint has moved.
#[error(
"the endpoint has moved{}",
.location.as_ref().map_or_default(|location| format!(" to {location}"))
)]
Moved {
/// The value of the `Location` header.
#[cfg_attr(
feature = "unstable-wasm",
serde(skip_serializing_if = "Option::is_none")
)]
location: Option<String>,
},
/// The server refuses this client (status 403). Trying again does not
/// help.
#[error("the server refused the request")]
Blocked,
/// The client sent too many requests (status 429). Trying again later
/// can help.
#[error("the server received too many requests")]
RateLimited,
/// The server rejected the credentials (status 401, or the code `AUTH`
/// in a HAFAS answer).
#[error("the server rejected the credentials")]
Unauthorized,
/// The server failed (status 5xx).
#[error("the server is unavailable")]
Unavailable,
/// The server reported any other failure: an HTTP status that no other
/// variant covers, or an error inside a successful response, as TRIAS,
/// OJP and HAFAS send them.
#[error("the server reported an error (HTTP status {status}): {message}")]
Server {
/// The HTTP status code. It is 200 for an error inside a successful
/// response.
status: u16,
/// The start of the response body, or the error code or text the
/// server put into a successful response.
message: String,
},
/// The response was not in the format the protocol defines.
#[error("the response could not be read: {message}")]
Parse {
/// What was wrong with the response.
message: String,
},
}