1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* 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 serde::Serialize;
use thiserror::Error;
#[doc = "API errors are in the 1XXXX range"]
#[derive(Debug, Serialize, 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,
#[doc = "For when pool.get() fails"]
#[error("database pool get failed")]
DatabasePoolGetFailed = 10003,
// 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,
#[doc = "Argon2 failed somehow"]
#[error("password hash failed")]
UserPasswordHashFailed = 11002,
#[doc = "Argon2 verify_password failed somehow"]
#[error("password check failed")]
UserPasswordCheckFailed = 11003,
// login/register 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,
}