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
66
67
68
use serde::{Deserialize, Serialize};
use serde_repr::*;
use crate::impl_visitable_noop;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(deny_unknown_fields))]
#[serde(rename_all = "camelCase")]
/// Should be handled as additional information for e.g. debugging.
/// Contains information if an object is valid.
/// If not, a status code and maybe an additional message inform about what is wrong.
pub struct Status {
/// Describes status in short.
/// Default is 200, no errors detected.
pub code: StatusCode,
/// Optional message string contains additional information to better understand the status code.
pub message: Option<String>,
}
impl_visitable_noop!(Status);
impl Status {
pub fn new_ok() -> Status {
Status {
code: StatusCode::Ok,
message: None,
}
}
pub fn new(code: StatusCode, message: Option<String>) -> Status {
Status { code, message }
}
}
impl Default for Status {
fn default() -> Self {
Status::new_ok()
}
}
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema_repr))]
#[repr(u16)]
/// Defines status codes on product and scene level.
/// 200 is default. All other codes than 200 are errors.
/// Codes <= 1000 are reserved except the predefined ones.
/// Codes > 1000 are user defined error codes.
pub enum StatusCode {
/// No errors detected.
Ok = 200,
/// Not sufficient defined or invalid parameters.
BadRequest = 400,
/// Data for further processing not found.
NotFound = 404,
/// One or more errors occurred.
Conflict = 409,
/// An error during data processing occurred.
InternalServerError = 500,
/// Service for data processing/gathering not available.
ServiceUnavailable = 503,
}