rightkit_daemon/contract/
status.rs1use crate::error::*;
2use crate::ServiceError;
3
4pub const STATUS_TABLE: &[(&str, u16)] = &[
7 ("bad_request", 400),
8 (ERROR_UNAUTHENTICATED, 401),
9 (ERROR_RATE_LIMITED, 429),
10 (ERROR_FORBIDDEN, 403),
11 (ERROR_NOT_ALLOWED, 403),
12 (ERROR_REVISION_CONFLICT, 409),
13 (ERROR_RESPONSE_TOO_LARGE, 502),
14 (ERROR_REQUEST_TOO_LARGE, 413),
15 (ERROR_BAD_CHUNK, 400),
16 (ERROR_CONNECTION_CLOSED, 502),
17 (ERROR_HOST_HANDOFF, 503),
18 (ERROR_UNAVAILABLE, 503),
19 (ERROR_TIMEOUT, 504),
20 (ERROR_HOST_IDENTITY, 502),
21 (ERROR_SUITE_UNRESOLVED, 500),
22];
23
24pub fn status_for_code(code: &str) -> Option<u16> {
26 STATUS_TABLE
27 .iter()
28 .find(|(c, _)| *c == code)
29 .map(|(_, s)| *s)
30}
31
32pub fn status_for_error(e: &ServiceError) -> u16 {
34 status_for_code(&e.code).unwrap_or(if e.retryable { 503 } else { 500 })
35}