diff --git a/CHANGELOG.md b/CHANGELOG.md index 906cb87..6447a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- +- Return correct error variants for API errors ([#30](https://github.com/Nitrokey/nethsm-sdk-rs/issues/30)) [All Changes](https://github.com/Nitrokey/nethsm-sdk-rs/compare/v1.1.0...HEAD) diff --git a/generator/src/main/resources/crust/reqwest/api.mustache b/generator/src/main/resources/crust/reqwest/api.mustache index 678e196..14942d9 100644 --- a/generator/src/main/resources/crust/reqwest/api.mustache +++ b/generator/src/main/resources/crust/reqwest/api.mustache @@ -115,6 +115,32 @@ pub enum {{{operationIdCamelCase}}}Error { UnknownValue(serde_json::Value), } +impl {{{operationIdCamelCase}}}Error { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + {{#responses}} + {{#is4xx}} + {{code}} => Ok(Self::Status{{code}}()), + {{/is4xx}} + {{#is5xx}} + {{code}} => Ok(Self::Status{{code}}()), + {{/is5xx}} + {{#isDefault}} + {{code}} => Ok(Self::DefaultResponse()), + {{/isDefault}} + {{/responses}} + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + {{/operation}} {{/operations}} @@ -373,7 +399,8 @@ pub fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allPar _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { {{#returnType}} {{#vendorExtensions.x-produceMultipleMediaTypes}} if is_json { @@ -402,7 +429,7 @@ pub fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allPar ResponseContent::unit(local_var_resp) {{/returnType}} } else { - ResponseContent::deserialized(local_var_resp) + ResponseContent::new(local_var_resp, |data| {{{operationIdCamelCase}}}Error::new(local_var_status, data).map_err(From::from)) .and_then(|content| Err(Error::ResponseError(content))) } } diff --git a/src/apis/default_api.rs b/src/apis/default_api.rs index efcb41f..3bf0089 100644 --- a/src/apis/default_api.rs +++ b/src/apis/default_api.rs @@ -79,6 +79,26 @@ pub enum ConfigBackupPassphrasePutError { UnknownValue(serde_json::Value), } +impl ConfigBackupPassphrasePutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_logging_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -90,6 +110,25 @@ pub enum ConfigLoggingGetError { UnknownValue(serde_json::Value), } +impl ConfigLoggingGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_logging_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -102,6 +141,26 @@ pub enum ConfigLoggingPutError { UnknownValue(serde_json::Value), } +impl ConfigLoggingPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_network_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -113,6 +172,25 @@ pub enum ConfigNetworkGetError { UnknownValue(serde_json::Value), } +impl ConfigNetworkGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_network_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -125,6 +203,26 @@ pub enum ConfigNetworkPutError { UnknownValue(serde_json::Value), } +impl ConfigNetworkPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_time_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -136,6 +234,25 @@ pub enum ConfigTimeGetError { UnknownValue(serde_json::Value), } +impl ConfigTimeGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_time_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -148,6 +265,26 @@ pub enum ConfigTimePutError { UnknownValue(serde_json::Value), } +impl ConfigTimePutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_tls_cert_pem_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -160,6 +297,26 @@ pub enum ConfigTlsCertPemGetError { UnknownValue(serde_json::Value), } +impl ConfigTlsCertPemGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + 415 => Ok(Self::Status415()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_tls_cert_pem_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -172,6 +329,26 @@ pub enum ConfigTlsCertPemPutError { UnknownValue(serde_json::Value), } +impl ConfigTlsCertPemPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_tls_csr_pem_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -183,6 +360,25 @@ pub enum ConfigTlsCsrPemPostError { UnknownValue(serde_json::Value), } +impl ConfigTlsCsrPemPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_tls_generate_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -195,6 +391,26 @@ pub enum ConfigTlsGeneratePostError { UnknownValue(serde_json::Value), } +impl ConfigTlsGeneratePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_tls_public_pem_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -206,6 +422,25 @@ pub enum ConfigTlsPublicPemGetError { UnknownValue(serde_json::Value), } +impl ConfigTlsPublicPemGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_unattended_boot_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -217,6 +452,25 @@ pub enum ConfigUnattendedBootGetError { UnknownValue(serde_json::Value), } +impl ConfigUnattendedBootGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_unattended_boot_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -229,6 +483,26 @@ pub enum ConfigUnattendedBootPutError { UnknownValue(serde_json::Value), } +impl ConfigUnattendedBootPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`config_unlock_passphrase_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -241,6 +515,26 @@ pub enum ConfigUnlockPassphrasePutError { UnknownValue(serde_json::Value), } +impl ConfigUnlockPassphrasePutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`health_alive_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -250,6 +544,23 @@ pub enum HealthAliveGetError { UnknownValue(serde_json::Value), } +impl HealthAliveGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`health_ready_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -259,6 +570,23 @@ pub enum HealthReadyGetError { UnknownValue(serde_json::Value), } +impl HealthReadyGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`health_state_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -267,6 +595,22 @@ pub enum HealthStateGetError { UnknownValue(serde_json::Value), } +impl HealthStateGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 406 => Ok(Self::Status406()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`info_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -275,6 +619,22 @@ pub enum InfoGetError { UnknownValue(serde_json::Value), } +impl InfoGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 406 => Ok(Self::Status406()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_generate_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -287,6 +647,26 @@ pub enum KeysGeneratePostError { UnknownValue(serde_json::Value), } +impl KeysGeneratePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -298,6 +678,25 @@ pub enum KeysGetError { UnknownValue(serde_json::Value), } +impl KeysGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_cert_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -310,6 +709,26 @@ pub enum KeysKeyIdCertDeleteError { UnknownValue(serde_json::Value), } +impl KeysKeyIdCertDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_cert_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -323,6 +742,27 @@ pub enum KeysKeyIdCertGetError { UnknownValue(serde_json::Value), } +impl KeysKeyIdCertGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_cert_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -335,6 +775,26 @@ pub enum KeysKeyIdCertPutError { UnknownValue(serde_json::Value), } +impl KeysKeyIdCertPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 409 => Ok(Self::Status409()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_csr_pem_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -348,6 +808,27 @@ pub enum KeysKeyIdCsrPemPostError { UnknownValue(serde_json::Value), } +impl KeysKeyIdCsrPemPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_decrypt_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -361,6 +842,27 @@ pub enum KeysKeyIdDecryptPostError { UnknownValue(serde_json::Value), } +impl KeysKeyIdDecryptPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -373,6 +875,26 @@ pub enum KeysKeyIdDeleteError { UnknownValue(serde_json::Value), } +impl KeysKeyIdDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_encrypt_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -386,6 +908,27 @@ pub enum KeysKeyIdEncryptPostError { UnknownValue(serde_json::Value), } +impl KeysKeyIdEncryptPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -399,6 +942,27 @@ pub enum KeysKeyIdGetError { UnknownValue(serde_json::Value), } +impl KeysKeyIdGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_public_pem_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -412,6 +976,27 @@ pub enum KeysKeyIdPublicPemGetError { UnknownValue(serde_json::Value), } +impl KeysKeyIdPublicPemGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -425,6 +1010,27 @@ pub enum KeysKeyIdPutError { UnknownValue(serde_json::Value), } +impl KeysKeyIdPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 409 => Ok(Self::Status409()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_restrictions_tags_tag_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -437,6 +1043,26 @@ pub enum KeysKeyIdRestrictionsTagsTagDeleteError { UnknownValue(serde_json::Value), } +impl KeysKeyIdRestrictionsTagsTagDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_restrictions_tags_tag_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -450,6 +1076,27 @@ pub enum KeysKeyIdRestrictionsTagsTagPutError { UnknownValue(serde_json::Value), } +impl KeysKeyIdRestrictionsTagsTagPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_key_id_sign_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -463,6 +1110,27 @@ pub enum KeysKeyIdSignPostError { UnknownValue(serde_json::Value), } +impl KeysKeyIdSignPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`keys_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -475,6 +1143,26 @@ pub enum KeysPostError { UnknownValue(serde_json::Value), } +impl KeysPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`lock_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -486,6 +1174,25 @@ pub enum LockPostError { UnknownValue(serde_json::Value), } +impl LockPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`metrics_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -497,6 +1204,25 @@ pub enum MetricsGetError { UnknownValue(serde_json::Value), } +impl MetricsGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`namespaces_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -508,6 +1234,25 @@ pub enum NamespacesGetError { UnknownValue(serde_json::Value), } +impl NamespacesGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`namespaces_namespace_id_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -520,6 +1265,26 @@ pub enum NamespacesNamespaceIdDeleteError { UnknownValue(serde_json::Value), } +impl NamespacesNamespaceIdDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`namespaces_namespace_id_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -533,6 +1298,27 @@ pub enum NamespacesNamespaceIdPutError { UnknownValue(serde_json::Value), } +impl NamespacesNamespaceIdPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 409 => Ok(Self::Status409()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`provision_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -543,6 +1329,24 @@ pub enum ProvisionPostError { UnknownValue(serde_json::Value), } +impl ProvisionPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`random_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -555,6 +1359,26 @@ pub enum RandomPostError { UnknownValue(serde_json::Value), } +impl RandomPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_backup_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -566,6 +1390,25 @@ pub enum SystemBackupPostError { UnknownValue(serde_json::Value), } +impl SystemBackupPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_cancel_update_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -577,6 +1420,25 @@ pub enum SystemCancelUpdatePostError { UnknownValue(serde_json::Value), } +impl SystemCancelUpdatePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_commit_update_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -588,6 +1450,25 @@ pub enum SystemCommitUpdatePostError { UnknownValue(serde_json::Value), } +impl SystemCommitUpdatePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_factory_reset_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -599,6 +1480,25 @@ pub enum SystemFactoryResetPostError { UnknownValue(serde_json::Value), } +impl SystemFactoryResetPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_info_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -610,6 +1510,25 @@ pub enum SystemInfoGetError { UnknownValue(serde_json::Value), } +impl SystemInfoGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_reboot_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -621,6 +1540,25 @@ pub enum SystemRebootPostError { UnknownValue(serde_json::Value), } +impl SystemRebootPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_restore_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -631,6 +1569,24 @@ pub enum SystemRestorePostError { UnknownValue(serde_json::Value), } +impl SystemRestorePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_shutdown_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -642,6 +1598,25 @@ pub enum SystemShutdownPostError { UnknownValue(serde_json::Value), } +impl SystemShutdownPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`system_update_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -655,6 +1630,27 @@ pub enum SystemUpdatePostError { UnknownValue(serde_json::Value), } +impl SystemUpdatePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 409 => Ok(Self::Status409()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`unlock_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -666,6 +1662,25 @@ pub enum UnlockPostError { UnknownValue(serde_json::Value), } +impl UnlockPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -677,6 +1692,25 @@ pub enum UsersGetError { UnknownValue(serde_json::Value), } +impl UsersGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -689,6 +1723,26 @@ pub enum UsersPostError { UnknownValue(serde_json::Value), } +impl UsersPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -702,6 +1756,27 @@ pub enum UsersUserIdDeleteError { UnknownValue(serde_json::Value), } +impl UsersUserIdDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -715,6 +1790,27 @@ pub enum UsersUserIdGetError { UnknownValue(serde_json::Value), } +impl UsersUserIdGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_passphrase_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -728,6 +1824,27 @@ pub enum UsersUserIdPassphrasePostError { UnknownValue(serde_json::Value), } +impl UsersUserIdPassphrasePostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_post`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -740,6 +1857,26 @@ pub enum UsersUserIdPostError { UnknownValue(serde_json::Value), } +impl UsersUserIdPostError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -753,6 +1890,27 @@ pub enum UsersUserIdPutError { UnknownValue(serde_json::Value), } +impl UsersUserIdPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 406 => Ok(Self::Status406()), + 409 => Ok(Self::Status409()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_tags_get`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -766,6 +1924,27 @@ pub enum UsersUserIdTagsGetError { UnknownValue(serde_json::Value), } +impl UsersUserIdTagsGetError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_tags_tag_delete`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -778,6 +1957,26 @@ pub enum UsersUserIdTagsTagDeleteError { UnknownValue(serde_json::Value), } +impl UsersUserIdTagsTagDeleteError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// struct for typed errors of method [`users_user_id_tags_tag_put`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] @@ -791,6 +1990,27 @@ pub enum UsersUserIdTagsTagPutError { UnknownValue(serde_json::Value), } +impl UsersUserIdTagsTagPutError { + fn new(status: u16, data: &[u8]) -> Result { + // to do: support payloads once added to API spec + match status { + 400 => Ok(Self::Status400()), + 401 => Ok(Self::Status401()), + 403 => Ok(Self::Status403()), + 404 => Ok(Self::Status404()), + 406 => Ok(Self::Status406()), + 412 => Ok(Self::Status412()), + _ => { + if data.is_empty() { + Ok(Self::UnknownValue(serde_json::Value::Null)) + } else { + serde_json::from_slice(data).map(Self::UnknownValue) + } + } + } + } +} + /// Update the backup passphrase. If the backup passphrase is not set yet, use \"\" as currentPassphrase. *WARNING:* Like the unlock passphrase, this configuration can't be reset by an admin user without knowing the current value, so if the backup passphrase is lost, neither can it be reset to a new value nor can the created backups be restored. pub fn config_backup_passphrase_put( @@ -824,11 +2044,14 @@ pub fn config_backup_passphrase_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigBackupPassphrasePutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -862,11 +2085,14 @@ pub fn config_logging_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigLoggingGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -900,11 +2126,14 @@ pub fn config_logging_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigLoggingPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -938,11 +2167,14 @@ pub fn config_network_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigNetworkGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -976,11 +2208,14 @@ pub fn config_network_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigNetworkPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1014,11 +2249,14 @@ pub fn config_time_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTimeGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1052,11 +2290,14 @@ pub fn config_time_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTimePutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1090,11 +2331,14 @@ pub fn config_tls_cert_pem_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::string(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTlsCertPemGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1128,11 +2372,14 @@ pub fn config_tls_cert_pem_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTlsCertPemPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1168,11 +2415,14 @@ pub fn config_tls_csr_pem_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::string(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTlsCsrPemPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1206,11 +2456,14 @@ pub fn config_tls_generate_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTlsGeneratePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1247,11 +2500,14 @@ pub fn config_tls_public_pem_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::string(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigTlsPublicPemGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1289,11 +2545,14 @@ pub fn config_unattended_boot_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigUnattendedBootGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1330,11 +2589,14 @@ pub fn config_unattended_boot_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigUnattendedBootPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1371,11 +2633,14 @@ pub fn config_unlock_passphrase_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ConfigUnlockPassphrasePutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1402,11 +2667,14 @@ pub fn health_alive_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + HealthAliveGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1433,11 +2701,14 @@ pub fn health_ready_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + HealthReadyGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1466,11 +2737,14 @@ pub fn health_state_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + HealthStateGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1499,11 +2773,14 @@ pub fn info_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + InfoGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1539,11 +2816,14 @@ pub fn keys_generate_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysGeneratePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1582,11 +2862,14 @@ pub fn keys_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1623,11 +2906,14 @@ pub fn keys_key_id_cert_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdCertDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1666,11 +2952,14 @@ pub fn keys_key_id_cert_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::bytes(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdCertGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1710,11 +2999,14 @@ pub fn keys_key_id_cert_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdCertPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1755,11 +3047,14 @@ pub fn keys_key_id_csr_pem_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::string(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdCsrPemPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1800,11 +3095,14 @@ pub fn keys_key_id_decrypt_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdDecryptPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1841,11 +3139,14 @@ pub fn keys_key_id_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1886,11 +3187,14 @@ pub fn keys_key_id_encrypt_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdEncryptPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1929,11 +3233,14 @@ pub fn keys_key_id_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -1972,11 +3279,14 @@ pub fn keys_key_id_public_pem_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::string(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdPublicPemGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2021,11 +3331,14 @@ pub fn keys_key_id_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2064,11 +3377,14 @@ pub fn keys_key_id_restrictions_tags_tag_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdRestrictionsTagsTagDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2107,11 +3423,14 @@ pub fn keys_key_id_restrictions_tags_tag_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdRestrictionsTagsTagPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2152,11 +3471,14 @@ pub fn keys_key_id_sign_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysKeyIdSignPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2198,11 +3520,14 @@ pub fn keys_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + KeysPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2234,11 +3559,14 @@ pub fn lock_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + LockPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2272,11 +3600,14 @@ pub fn metrics_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + MetricsGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2310,11 +3641,14 @@ pub fn namespaces_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + NamespacesGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2351,11 +3685,14 @@ pub fn namespaces_namespace_id_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + NamespacesNamespaceIdDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2392,11 +3729,14 @@ pub fn namespaces_namespace_id_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + NamespacesNamespaceIdPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2425,11 +3765,14 @@ pub fn provision_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + ProvisionPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2465,11 +3808,14 @@ pub fn random_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + RandomPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2503,11 +3849,14 @@ pub fn system_backup_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::bytes(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemBackupPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2539,11 +3888,14 @@ pub fn system_cancel_update_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemCancelUpdatePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2575,11 +3927,14 @@ pub fn system_commit_update_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemCommitUpdatePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2611,11 +3966,14 @@ pub fn system_factory_reset_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemFactoryResetPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2649,11 +4007,14 @@ pub fn system_info_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemInfoGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2685,11 +4046,14 @@ pub fn system_reboot_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemRebootPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2751,11 +4115,14 @@ pub fn system_restore_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemRestorePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2787,11 +4154,14 @@ pub fn system_shutdown_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemShutdownPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2828,11 +4198,14 @@ pub fn system_update_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + SystemUpdatePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2861,11 +4234,14 @@ pub fn unlock_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UnlockPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2899,11 +4275,14 @@ pub fn users_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2939,11 +4318,14 @@ pub fn users_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -2980,11 +4362,14 @@ pub fn users_user_id_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3023,11 +4408,14 @@ pub fn users_user_id_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3066,11 +4454,14 @@ pub fn users_user_id_passphrase_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdPassphrasePostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3111,11 +4502,14 @@ pub fn users_user_id_post( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdPostError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3154,11 +4548,14 @@ pub fn users_user_id_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3197,11 +4594,14 @@ pub fn users_user_id_tags_get( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::deserialized(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdTagsGetError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3240,11 +4640,14 @@ pub fn users_user_id_tags_tag_delete( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdTagsTagDeleteError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } @@ -3283,10 +4686,13 @@ pub fn users_user_id_tags_tag_put( _ => Err(err), })?; - if local_var_resp.status() < 400 { + let local_var_status = local_var_resp.status(); + if local_var_status < 400 { ResponseContent::unit(local_var_resp) } else { - ResponseContent::deserialized(local_var_resp) - .and_then(|content| Err(Error::ResponseError(content))) + ResponseContent::new(local_var_resp, |data| { + UsersUserIdTagsTagPutError::new(local_var_status, data).map_err(From::from) + }) + .and_then(|content| Err(Error::ResponseError(content))) } } diff --git a/tests/basic.rs b/tests/basic.rs index 2dae3c7..67f4428 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -22,7 +22,7 @@ async fn test_health_state() { } #[tokio::test] -async fn test_error() { +async fn test_error_with_body() { utils::with_container(|config| { let err = default_api::keys_get(&config, None).err().unwrap(); match err { @@ -33,6 +33,10 @@ async fn test_error() { err.contains("Service not available"), "unexpected error message: {err}" ); + match content.entity { + default_api::KeysGetError::Status412() => {} + err => panic!("Unexpected error variant: {err:?}"), + } } _ => { panic!("Unexpected error variant: {err:?}");