wick_trigger_http/http/
error.rs

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
use wick_config::config::Codec;
use wick_packet::Entity;

#[derive(Debug, thiserror::Error)]
#[allow(clippy::exhaustive_enums)]
pub enum HttpError {
  #[error("Internal error: {:?}",.0)]
  InternalError(InternalError),

  #[error("Operation error: {0}")]
  OperationError(String),

  #[error("Error in stream for '{0}': {1}")]
  OutputStream(String, String),

  #[error("Unsupported HTTP method: {0}")]
  UnsupportedMethod(String),

  #[error("Unsupported HTTP version: {0}")]
  UnsupportedVersion(String),

  #[error("Missing query parameters: {}", .0.join(", "))]
  MissingQueryParameters(Vec<String>),

  #[error("Could not decode body as JSON: {0}")]
  InvalidBody(serde_json::Error),

  #[error("Invalid status code: {0}")]
  InvalidStatusCode(String),

  #[error("Invalid parameter value: {0}")]
  InvalidParameter(String),

  #[error("Could not serialize output into '{0}' codec: {1}")]
  Codec(Codec, String),

  #[error("Could not decode stream item as base64 bytes: {0}")]
  Bytes(String),

  #[error("Could not decode stream item as a utf-8 string: {0}")]
  Utf8Text(String),

  #[error("Could not decode stream item as HttpEvent: {0}")]
  HttpEvent(String),

  #[error("Invalid header name: {0}")]
  InvalidHeaderName(String),

  #[error("Invalid header value: {0}")]
  InvalidHeaderValue(String),

  #[error("Invalid path or query parameters: {0}")]
  InvalidUri(String),

  #[error("Invalid pre-request middleware response: {0}")]
  InvalidPreRequestResponse(String),

  #[error("Pre-request middleware '{0}' did not provide a request or response")]
  PreRequestResponseNoData(Entity),

  #[error("Post-request middleware '{0}' did not provide a response")]
  PostRequestResponseNoData(Entity),

  #[error("Invalid post-request middleware response: {0}")]
  InvalidPostRequestResponse(String),

  #[error("Error deserializing response on port {0}: {1}")]
  Deserialize(String, String),

  #[error("URI {0} could not be parsed: {1}")]
  RouteSyntax(String, String),

  #[error("{0}")]
  InitializationFailed(String),

  #[error("error in configuration: {0}")]
  Config(Box<wick_config::Error>),
}

#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub enum InternalError {
  Builder,
}

impl From<HttpError> for wick_trigger::Error {
  fn from(value: HttpError) -> Self {
    wick_trigger::Error::new_context("http", wick_trigger::error::ErrorKind::Trigger(Box::new(value)))
  }
}

impl From<wick_config::Error> for HttpError {
  fn from(value: wick_config::Error) -> Self {
    HttpError::Config(Box::new(value))
  }
}