studentvue/
error.rs

1//! Errors which may occur during xml parsing or when handling a web request
2use std::fmt;
3
4/// General StudentVUE error
5#[derive(Debug)]
6pub enum VueError {
7    Format(std::fmt::Error),
8    Xml(quick_xml::DeError),
9    Request(reqwest::Error)
10}
11
12impl From<std::fmt::Error> for VueError {
13    fn from(err: std::fmt::Error) -> VueError {
14        VueError::Format(err)
15    }
16}
17
18impl From<quick_xml::DeError> for VueError {
19    fn from(err: quick_xml::DeError) -> VueError {
20        VueError::Xml(err)
21    }
22}
23
24impl From<reqwest::Error> for VueError {
25    fn from(err: reqwest::Error) -> VueError {
26        VueError::Request(err)
27    }
28}
29
30impl fmt::Display for VueError {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            VueError::Request(e) => write!(f, "An error occured during the server request: {}", e),
34            VueError::Format(e) => write!(f, "Formatting error occured: {}", e),
35            VueError::Xml(e) => write!(f, "XML parsing error occured{}", e),
36        }
37    }
38}
39
40impl std::error::Error for VueError {}