Skip to content

Commit

Permalink
Added Supabase HTTP Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Proziam committed Sep 29, 2024
1 parent 18ff38d commit 6efb253
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::env;
use std::{
env,
fmt::{self, Display},
};

use serde::{Deserialize, Serialize};
use thiserror::Error;

#[derive(Debug, Error)]
Expand All @@ -26,4 +30,45 @@ pub enum Error {
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
#[error("Environment Variable Unreadable")]
InvalidEnvironmentVariable(#[from] env::VarError),
#[error("{0}")]
Supabase(SupabaseHTTPError),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SupabaseHTTPError {
pub code: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
#[serde(rename = "msg")]
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub internal_error: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub internal_message: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_id: Option<String>,
}

impl Display for SupabaseHTTPError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Status Code {}", self.code)?;

if let Some(error_code) = &self.error_code {
write!(f, " ({})", error_code)?;
}

if let Some(error_id) = &self.error_id {
write!(f, " [Error ID: {}]", error_id)?;
}

if let Some(internal_message) = &self.internal_message {
write!(f, "\nInternal message: {}", internal_message)?;
}

if let Some(internal_error) = &self.internal_error {
write!(f, "\nInternal error: {}", internal_error)?;
}

write!(f, "\nMessage: {}", self.message)
}
}

0 comments on commit 6efb253

Please sign in to comment.