grp_core/error/errors/
request.rs1use std::fmt::Display;
2
3use color_print::cformat;
4
5use crate::make_error;
6use crate::error::structs::Error;
7
8macro_rules! etype {
9 ($literal:literal) => { concat!("request::", $literal) };
10}
11
12pub struct Request;
13
14impl Request {
15 pub fn bad_token_scope<P, S>(pconf: P, scopes: Vec<S>) -> Error
16 where
17 P: Display,
18 S: Display,
19 {
20 if scopes.is_empty() { panic!("There are no scopes to show") }
21 let mut content: Vec<String> = Vec::with_capacity(3 + scopes.len());
22
23 content.push(cformat!("<y>* Please check your token.</>"));
24 content.push(cformat!(" <g>» Pconf: <m><<{}>></>", pconf));
25 content.push(cformat!(" <g>» You must add the following scopes: </>"));
26
27 content.extend(scopes.iter().map(|s| { cformat!(" <#e3750e>▸ <m>{}</>", s) }));
28
29 Error {
30 etype: etype!("bad_token_scope").to_string(),
31 message: "The token has insufficient permitions".to_string(),
32 content: content,
33 }
34 }
35
36 pub fn fetch<P, S>(message: P, notes: Vec<S>) -> Error
37 where
38 P: Display,
39 S: Display,
40 {
41 make_error!{
42 notes, etype!("fetch"), message,
43 0 of
44 }
45 }
46
47 pub fn unauthorized<P, S, K>(pconf: P, user: S, notes: Vec<K>) -> Error
48 where
49 P: Display,
50 S: Display,
51 K: Display,
52 {
53 make_error!{
54 notes, etype!("unauthorized"), "The token provided has no access to that resourse",
55 2 of
56 cformat!("<y>* Pconf: <m><<{}>></>", pconf),
57 cformat!("<y>* User: <m><<{}>></>", user),
58 }
59 }
60
61 pub fn unsuported<P, S, K>(platform: P, action: S, notes: Vec<K>) -> Error
62 where
63 P: Display,
64 S: Display,
65 K: Display,
66 {
67 make_error!{
68 notes, etype!("unsuported"), "The token provided has no access to that resourse",
69 1 of
70 cformat!("<y>* <m>{}</m> does not suppot <r,i>{}!</>", platform, action),
71 }
72 }
73
74 pub fn getting_body<P: Display>(error: P) -> Error {
75 make_error!{
76 etype!("get::body"), "Error getting the response body",
77 1 of
78 cformat!("<y>* {}</>", error),
79 }
80 }
81}