use core::fmt;
use std::collections::HashMap;
use serde::Deserialize;
use thiserror::Error;
pub use crate::records::auth::auth_with_password::AuthenticationError;
pub use crate::records::auth::impersonate::ImpersonateError;
pub use crate::records::crud::create::CreateError;
pub use crate::records::crud::update::UpdateError;
#[derive(Deserialize, Debug)]
pub struct BadRequestResponse {
pub status: u16,
pub message: String,
pub data: HashMap<String, BadRequestField>,
}
#[derive(Deserialize, Debug)]
pub struct BadRequestError {
pub name: String,
pub code: String,
pub message: String,
}
impl fmt::Display for BadRequestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {} {}", self.name, self.code, self.message)
}
}
#[derive(Deserialize, Debug)]
pub struct BadRequestField {
pub code: String,
pub message: String,
}
#[derive(Error, Debug)]
pub enum RequestError {
#[error("Bad Request: Something went wrong while processing your request. {0}")]
BadRequest(String),
#[error("Unauthorized: The request may require an Authorization Token.")]
Unauthorized,
#[error("Forbidden: The authenticated user may not have permissions for this interaction.")]
Forbidden,
#[error("Not Found: The requested resource could not be found.")]
NotFound,
#[error(
"Parse Error: Could not parse response into the expected data structure. It usually means that there is a missmatch between the provided Generic Type Parameter and your Collection definition. - {0}"
)]
ParseError(String),
#[error(
"Unreachable: The PocketBase API interaction timed out, or the service may be offline."
)]
Unreachable,
#[error(
"Too Many Requests: The server is rate limiting requests. Please wait before retrying."
)]
TooManyRequests,
#[error("Unhandled Error: An unexpected error occurred.")]
Unhandled,
}