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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! The framework's stable error codes: the `code` member of the JSON error
//! body.
//!
//! A front end maps `code` to a translation key, so a refusal reaches the
//! user in their own language whatever the English `message` says. These
//! values are part of Navree's public contract: they do not change between
//! releases, and new codes are only ever added.
//!
//! [`AppError::from_status`](crate::AppError::from_status) derives a code
//! from the status (the reason phrase in snake case, `unauthenticated` for
//! 401 and `internal_error` for 500); the constructors below set theirs.
//! Modules set more specific codes on their own errors (`invalid_credentials`,
//! `workspace_not_found`, ...), and apps set theirs with
//! [`AppError::with_code`](crate::AppError::with_code).
//!
//! | Code | Status | Sent by |
//! |---|---|---|
//! | `bad_request` | 400 | `AppError::bad_request`, malformed input |
//! | `validation_failed` | 400 | `AppError::validation`: field errors in `errors` |
//! | `invalid_filter` | 400 | `AppError::invalid_filter`: an unknown or malformed list filter |
//! | `unauthenticated` | 401 | `AppError::unauthenticated`: no user, or bad credentials |
//! | `two_factor_required` | 401 | `AppError::two_factor_required` |
//! | `invalid_signature` | 401 | a signed URL that does not verify |
//! | `forbidden` | 403 | `AppError::forbidden`: access control refuses |
//! | `csrf_token_mismatch` | 403 | the CSRF check fails |
//! | `demo_read_only` | 403 | `AppError::demo_read_only`: a write in a demo workspace |
//! | `not_found` | 404 | `AppError::not_found`, and a path no route matches |
//! | `method_not_allowed` | 405 | a path that exists for other methods |
//! | `conflict` | 409 | `AppError::conflict` |
//! | `limit_reached` | 409 | `AppError::limit_reached`: a plan or quota limit |
//! | `payload_too_large` | 413 | `AppError::payload_too_large` |
//! | `unsupported_media_type` | 415 | a JSON or form body of another content type |
//! | `page_expired` | 419 | `AppError::page_expired`: a page left open too long |
//! | `too_many_requests` | 429 | `AppError::too_many_requests`, rate limits |
//! | `internal_error` | 500 | `AppError::internal`, `?` on any error, panics |
//! | `service_unavailable` | 503 | `AppError::service_unavailable` |
//! | `maintenance` | 503 | maintenance mode |
//! | `request_timeout` | 503 | a request that ran out of time |
/// 400: malformed input ([`AppError::bad_request`](crate::AppError::bad_request)).
pub const BAD_REQUEST: &str = "bad_request";
/// 400 with field errors ([`AppError::validation`](crate::AppError::validation)).
pub const VALIDATION_FAILED: &str = "validation_failed";
/// 400: an unknown or malformed list filter
/// ([`AppError::invalid_filter`](crate::AppError::invalid_filter)).
pub const INVALID_FILTER: &str = "invalid_filter";
/// 401: the request is not authenticated
/// ([`AppError::unauthenticated`](crate::AppError::unauthenticated)).
pub const UNAUTHENTICATED: &str = "unauthenticated";
/// 401: the password was right but a second factor is needed
/// ([`AppError::two_factor_required`](crate::AppError::two_factor_required)).
pub const TWO_FACTOR_REQUIRED: &str = "two_factor_required";
/// 401: a signed URL whose signature is missing, wrong or expired.
pub const INVALID_SIGNATURE: &str = "invalid_signature";
/// 403: the user may not do this ([`AppError::forbidden`](crate::AppError::forbidden)).
pub const FORBIDDEN: &str = "forbidden";
/// 403: the CSRF token is missing or does not match the session
/// ([`AppError::csrf_mismatch`](crate::AppError::csrf_mismatch)).
pub const CSRF_TOKEN_MISMATCH: &str = "csrf_token_mismatch";
/// 403: a write in a demo workspace
/// ([`AppError::demo_read_only`](crate::AppError::demo_read_only)).
pub const DEMO_READ_ONLY: &str = "demo_read_only";
/// 404 ([`AppError::not_found`](crate::AppError::not_found)).
pub const NOT_FOUND: &str = "not_found";
/// 405: the path exists for other methods.
pub const METHOD_NOT_ALLOWED: &str = "method_not_allowed";
/// 409 ([`AppError::conflict`](crate::AppError::conflict)).
pub const CONFLICT: &str = "conflict";
/// 409: a plan or quota limit is reached
/// ([`AppError::limit_reached`](crate::AppError::limit_reached)).
pub const LIMIT_REACHED: &str = "limit_reached";
/// 413: the body is too large
/// ([`AppError::payload_too_large`](crate::AppError::payload_too_large)).
pub const PAYLOAD_TOO_LARGE: &str = "payload_too_large";
/// 415: a JSON or form body sent with another content type.
pub const UNSUPPORTED_MEDIA_TYPE: &str = "unsupported_media_type";
/// 419: a page that was open too long or whose session changed
/// ([`AppError::page_expired`](crate::AppError::page_expired)).
pub const PAGE_EXPIRED: &str = "page_expired";
/// 429: a rate limit is exceeded
/// ([`AppError::too_many_requests`](crate::AppError::too_many_requests)).
pub const TOO_MANY_REQUESTS: &str = "too_many_requests";
/// 500: an unexpected error or a panic ([`AppError::internal`](crate::AppError::internal)).
pub const INTERNAL_ERROR: &str = "internal_error";
/// 503 ([`AppError::service_unavailable`](crate::AppError::service_unavailable)).
pub const SERVICE_UNAVAILABLE: &str = "service_unavailable";
/// 503: the app is in maintenance mode.
pub const MAINTENANCE: &str = "maintenance";
/// 503: the request ran out of time.
pub const REQUEST_TIMEOUT: &str = "request_timeout";
/// Every code above, in the order of the table.
pub const ALL: & = &;
/// Whether `code` is a well-formed error code: 1 to 64 characters of
/// lower-case ASCII letters, digits and `_`, starting with a letter.