Move custom errros to central file
This commit is contained in:
parent
552b43f80b
commit
f96bcb87f6
|
@ -1,17 +1,10 @@
|
||||||
pub mod instance {
|
pub mod instance {
|
||||||
use custom_error::custom_error;
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
|
|
||||||
|
use crate::errors::InstancePoliciesError;
|
||||||
use crate::{api::schemas::schemas::InstancePoliciesSchema, instance::Instance};
|
use crate::{api::schemas::schemas::InstancePoliciesSchema, instance::Instance};
|
||||||
|
|
||||||
custom_error! {
|
|
||||||
#[derive(PartialEq, Eq)]
|
|
||||||
pub InstancePoliciesError
|
|
||||||
RequestErrorError{url:String, error:String} = "An error occured while trying to GET from {url}: {error}",
|
|
||||||
ReceivedErrorCodeError{error_code:String} = "Received the following error code while requesting from the route: {error_code}"
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
/**
|
/**
|
||||||
Gets the instance policies schema.
|
Gets the instance policies schema.
|
||||||
|
|
|
@ -5,6 +5,8 @@ pub mod schemas {
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::errors::RegisterSchemaError;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub struct RegisterSchema {
|
pub struct RegisterSchema {
|
||||||
|
@ -20,15 +22,6 @@ pub mod schemas {
|
||||||
promotional_email_opt_in: Option<bool>,
|
promotional_email_opt_in: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
custom_error! {
|
|
||||||
#[derive(PartialEq, Eq)]
|
|
||||||
pub RegisterSchemaError
|
|
||||||
PasswordError = "Password must be between 1 and 72 characters.",
|
|
||||||
UsernameError = "Username must be between 2 and 32 characters.",
|
|
||||||
ConsentError = "Consent must be 'true' to register.",
|
|
||||||
EmailError = "The provided email address is in an invalid format."
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RegisterSchema {
|
impl RegisterSchema {
|
||||||
/**
|
/**
|
||||||
Returns a new [`Result<RegisterSchema, RegisterSchemaError>`].
|
Returns a new [`Result<RegisterSchema, RegisterSchemaError>`].
|
||||||
|
@ -166,6 +159,7 @@ pub mod schemas {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod schemas_tests {
|
mod schemas_tests {
|
||||||
use super::schemas::*;
|
use super::schemas::*;
|
||||||
|
use crate::errors::RegisterSchemaError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn password_too_short() {
|
fn password_too_short() {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
use custom_error::custom_error;
|
||||||
|
|
||||||
|
custom_error! {
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
pub InstancePoliciesError
|
||||||
|
RequestErrorError{url:String, error:String} = "An error occured while trying to GET from {url}: {error}",
|
||||||
|
ReceivedErrorCodeError{error_code:String} = "Received the following error code while requesting from the route: {error_code}"
|
||||||
|
}
|
||||||
|
|
||||||
|
custom_error! {
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
pub RegisterSchemaError
|
||||||
|
PasswordError = "Password must be between 1 and 72 characters.",
|
||||||
|
UsernameError = "Username must be between 2 and 32 characters.",
|
||||||
|
ConsentError = "Consent must be 'true' to register.",
|
||||||
|
EmailError = "The provided email address is in an invalid format."
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
mod api;
|
mod api;
|
||||||
|
mod errors;
|
||||||
mod gateway;
|
mod gateway;
|
||||||
mod instance;
|
mod instance;
|
||||||
mod limit;
|
mod limit;
|
||||||
|
|
Loading…
Reference in New Issue