tosho_kmkc/models/
errors.rs1use tosho_common::{ToshoError, make_error};
6
7#[derive(Debug)]
9pub struct KMAPIError {
10 pub error_code: i32,
12 pub message: String,
14}
15
16impl std::fmt::Display for KMAPIError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 write!(
19 f,
20 "An error occurred with status {}: {}",
21 self.error_code, self.message
22 )
23 }
24}
25
26impl std::error::Error for KMAPIError {}
27
28#[derive(Debug)]
30pub struct KMAPINotEnoughPointsError {
31 pub message: String,
33 pub points_needed: u64,
35 pub points_have: u64,
37}
38
39impl std::fmt::Display for KMAPINotEnoughPointsError {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(
42 f,
43 "{} ({} points needed, {} points have)",
44 self.message, self.points_needed, self.points_have
45 )
46 }
47}
48
49impl std::error::Error for KMAPINotEnoughPointsError {}
50
51impl From<KMAPIError> for ToshoError {
52 fn from(value: KMAPIError) -> Self {
53 make_error!("{}", value)
54 }
55}
56
57impl From<KMAPINotEnoughPointsError> for ToshoError {
58 fn from(value: KMAPINotEnoughPointsError) -> Self {
59 make_error!("{}", value)
60 }
61}