Move custom errros to central file
This commit is contained in:
parent
1c2a60613b
commit
06bc2955a3
|
@ -1,17 +1,10 @@
|
|||
pub mod instance {
|
||||
use custom_error::custom_error;
|
||||
use reqwest::Client;
|
||||
use serde_json::from_str;
|
||||
|
||||
use crate::errors::InstancePoliciesError;
|
||||
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 {
|
||||
/**
|
||||
Gets the instance policies schema.
|
||||
|
|
|
@ -5,6 +5,8 @@ pub mod schemas {
|
|||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::errors::RegisterSchemaError;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct RegisterSchema {
|
||||
|
@ -20,15 +22,6 @@ pub mod schemas {
|
|||
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 {
|
||||
/**
|
||||
Returns a new [`Result<RegisterSchema, RegisterSchemaError>`].
|
||||
|
@ -166,6 +159,7 @@ pub mod schemas {
|
|||
#[cfg(test)]
|
||||
mod schemas_tests {
|
||||
use super::schemas::*;
|
||||
use crate::errors::RegisterSchemaError;
|
||||
|
||||
#[test]
|
||||
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 errors;
|
||||
mod gateway;
|
||||
mod instance;
|
||||
mod limit;
|
||||
|
|
Loading…
Reference in New Issue