Skip to content

Commit b71b5bb

Browse files
Merge pull request #6 from emmanuelantony2000/error_type
Created a basic Error type
2 parents 18669e6 + fca8edf commit b71b5bb

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
thiserror = "1.0.24"

src/error.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use thiserror::Error;
2+
3+
/// [`Result`](std::result::Result) type that is returned from functions with error
4+
/// as [`TypesenseError`](crate::error::TypesenseError).
5+
pub type Result<T> = std::result::Result<T, TypesenseError>;
6+
7+
/// Represents an error that can occur while using the library.
8+
#[derive(Error, Debug)]
9+
pub enum TypesenseError {
10+
/// Config error.
11+
#[error("config error")]
12+
ConfigError,
13+
14+
/// Timeout.
15+
#[error("timeout")]
16+
Timeout,
17+
18+
/// Request malformed.
19+
#[error("request malformed")]
20+
RequestMalformed,
21+
22+
/// Request unauthorized.
23+
#[error("request unauthorized")]
24+
RequestUnauthorized,
25+
26+
/// Request forbidden.
27+
#[error("request forbidden")]
28+
RequestForbidden,
29+
30+
/// Object not found.
31+
#[error("object not found")]
32+
ObjectNotFound,
33+
34+
/// Object already exists.
35+
#[error("object already exists")]
36+
ObjectAlreadyExists,
37+
38+
/// Object unprocessable.
39+
#[error("object unprocessable")]
40+
ObjectUnprocessable,
41+
42+
/// Server error.
43+
#[error("server error")]
44+
ServerError,
45+
46+
/// Service unavailable.
47+
#[error("service unavailable")]
48+
ServiceUnavailable,
49+
50+
/// HTTP status error.
51+
#[error("HTTP status error")]
52+
HttpStatusError,
53+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
//! # Typesense
33
//!
44
//! Welcome to typesense, the rust library for the Typesense API.
5+
6+
mod error;
7+
8+
pub use error::{Result, TypesenseError};

0 commit comments

Comments
 (0)