Skip to content

Commit

Permalink
Add validation exception (#71)
Browse files Browse the repository at this point in the history
* add validation exception
  • Loading branch information
ByteOtter authored Apr 23, 2024
1 parent af967b2 commit 9dd86c5
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/publisher/publisher_exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
use reqwest::Error as ReqwestError;

use std::{error::Error, fmt};

use crate::configuration;
use std::{error::Error, fmt, process};

#[derive(Debug)]
pub enum NetBoxApiError {
Expand All @@ -48,3 +46,28 @@ impl From<ReqwestError> for NetBoxApiError {
NetBoxApiError::Reqwest(err)
}
}

/// Error to be thrown when the validation of an API request payload fails.
///
/// # Members
///
/// * message: `String` - The error message containing the reason for the failure.
pub struct PayloadValidationError {
message: String,
}

/// Implements the `Format` trait for `PayloadValidationError` for easy printing.
impl fmt::Display for PayloadValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[FATAL] PayloadValidationError: {}", self.message)
}
}

/// Implement `abort` function to exit the program in an orderly manner, printing the error message
/// in the process.
impl PayloadValidationError {
pub fn abort(&self, exit_code: i32) -> ! {
println!("{} (Error code: {})", self, exit_code);
process::exit(exit_code);
}
}

0 comments on commit 9dd86c5

Please sign in to comment.