M Cargo.lock => Cargo.lock +5 -4
@@ 5361,6 5361,7 @@ name = "shared"
version = "0.1.0"
dependencies = [
"naia-bevy-shared",
+ "thiserror",
]
[[package]]
@@ 5659,18 5660,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.37"
+version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
+checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.37"
+version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
+checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
M shared/Cargo.toml => shared/Cargo.toml +2 -0
@@ 11,3 11,5 @@ publish = false
[dependencies]
naia-bevy-shared = "0.16.0"
+
+thiserror = "1.0.38"
A shared/src/error/api.rs => shared/src/error/api.rs +52 -0
@@ 0,0 1,52 @@
+/*
+ * This file is part of laurelin/shared
+ * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
+ *
+ * Licensed under GPL-3.0-only.
+ * See LICENSE for licensing information.
+ */
+
+use thiserror::Error;
+
+#[doc = "API errors are in the 1XXXX range"]
+#[derive(Debug, Error)]
+pub enum APIError {
+ // general errors
+ #[doc = "Should never be used, but still exists just in case"]
+ #[error("undefined error")]
+ Undefined = 10000,
+
+ #[doc = "Authorization doesn't meet requirements"]
+ #[error("not authorized")]
+ NotAuthorized = 10001,
+
+ #[doc = "Authorization is missing from the request"]
+ #[error("missing authorization")]
+ MissingAuthorization = 10002,
+
+ // user related errors
+ #[doc = "User does not exist in the database"]
+ #[error("user not found")]
+ UserNotFound = 11000,
+
+ #[doc = "Invalid credentials were passed"]
+ #[error("invalid credentials")]
+ UserInvalidCredentials = 11001,
+
+ // login errors
+ #[doc = ""]
+ #[error("invalid email")]
+ UserEmailInvalid = 11100,
+
+ #[doc = ""]
+ #[error("username should not be shorter than 3 characters")]
+ UserUsernameTooShort = 11101,
+
+ #[doc = ""]
+ #[error("password should not be shorter than 8 characters")]
+ UserPasswordTooShort = 11102,
+
+ #[doc = ""]
+ #[error("user creation failed")]
+ UserCreationFailed = 11103,
+}
A shared/src/error/mod.rs => shared/src/error/mod.rs +9 -0
@@ 0,0 1,9 @@
+/*
+ * This file is part of laurelin/shared
+ * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
+ *
+ * Licensed under GPL-3.0-only.
+ * See LICENSE for licensing information.
+ */
+
+mod api;
M shared/src/lib.rs => shared/src/lib.rs +1 -0
@@ 6,4 6,5 @@
* See LICENSE for licensing information.
*/
+pub mod error;
pub mod server;