vector/sources/aws_kinesis_firehose/
errors.rs1use snafu::Snafu;
2use warp::http::StatusCode;
3
4use super::handlers::RecordDecodeError;
5
6#[derive(Debug, Snafu)]
7#[snafu(visibility(pub(crate)))]
8pub enum RequestError {
9 #[snafu(display(
10 "Missing access key. X-Amz-Firehose-Access-Key required for request: {}",
11 request_id
12 ))]
13 AccessKeyMissing { request_id: String },
14 #[snafu(display(
15 "Invalid access key. X-Amz-Firehose-Access-Key does not match configured access_key for request: {}",
16 request_id
17 ))]
18 AccessKeyInvalid { request_id: String },
19 #[snafu(display("Could not parse incoming request {}: {}", request_id, source))]
20 Parse {
21 source: serde_json::error::Error,
22 request_id: String,
23 },
24 #[snafu(display(
25 "Could not parse records from incoming request {}: {}",
26 request_id,
27 source
28 ))]
29 ParseRecords {
30 source: RecordDecodeError,
31 request_id: String,
32 },
33 #[snafu(display("Could not decode record for request {}: {}", request_id, source))]
34 Decode {
35 source: std::io::Error,
36 request_id: String,
37 },
38 #[snafu(display("Could not forward events for request {request_id}, downstream is closed"))]
39 ShuttingDown { request_id: String },
40 #[snafu(display("Unsupported encoding: {}", encoding))]
41 UnsupportedEncoding {
42 encoding: String,
43 request_id: String,
44 },
45 #[snafu(display("Unsupported protocol version: {}", version))]
46 UnsupportedProtocolVersion { version: String },
47 #[snafu(display("Delivery errored"))]
48 DeliveryErrored { request_id: String },
49 #[snafu(display("Delivery failed"))]
50 DeliveryFailed { request_id: String },
51}
52
53impl warp::reject::Reject for RequestError {}
54
55impl RequestError {
56 pub const fn status(&self) -> StatusCode {
57 use RequestError::*;
58 match *self {
59 AccessKeyMissing { .. } => StatusCode::UNAUTHORIZED,
60 AccessKeyInvalid { .. } => StatusCode::UNAUTHORIZED,
61 Parse { .. } => StatusCode::UNAUTHORIZED,
62 UnsupportedEncoding { .. } => StatusCode::BAD_REQUEST,
63 ParseRecords { .. } => StatusCode::BAD_REQUEST,
64 Decode { .. } => StatusCode::BAD_REQUEST,
65 ShuttingDown { .. } => StatusCode::SERVICE_UNAVAILABLE,
66 UnsupportedProtocolVersion { .. } => StatusCode::BAD_REQUEST,
67 DeliveryErrored { .. } => StatusCode::INTERNAL_SERVER_ERROR,
68 DeliveryFailed { .. } => StatusCode::NOT_ACCEPTABLE,
69 }
70 }
71
72 #[allow(clippy::missing_const_for_fn)] pub fn request_id(&self) -> Option<&str> {
74 use RequestError::*;
75 match *self {
76 AccessKeyMissing { ref request_id, .. } => Some(request_id),
77 AccessKeyInvalid { ref request_id, .. } => Some(request_id),
78 Parse { ref request_id, .. } => Some(request_id),
79 UnsupportedEncoding { ref request_id, .. } => Some(request_id),
80 ParseRecords { ref request_id, .. } => Some(request_id),
81 Decode { ref request_id, .. } => Some(request_id),
82 ShuttingDown { ref request_id, .. } => Some(request_id),
83 UnsupportedProtocolVersion { .. } => None,
84 DeliveryErrored { ref request_id } => Some(request_id),
85 DeliveryFailed { ref request_id } => Some(request_id),
86 }
87 }
88}