1 /** 
2  * Error handling definitions
3  */
4 module eskomcalendar.exceptions;
5 
6 import std.conv : to;
7 
8 /** 
9  * Kind-of error that occurred
10  */
11 public enum ErrType
12 {
13     /** 
14      * If there are no areas available
15      */
16     NO_AREAS_AVAILABLE,
17 
18     /** 
19      * If there were no schedules available
20      * for the given area
21      */
22     NO_SCHEDULES_AVAILABLE,
23 
24     /** 
25      * On error parsing schedule data
26      */
27     INVALID_SCHEDULE_DATA,
28 
29     /** 
30      * On error contacting the calendar server
31      */
32     NETWORK_ERROR
33 }
34 
35 /** 
36  * Represents an error that occurs using the `EskomCalendar` API
37  */
38 public final class EskomCalendarException : Exception
39 {
40     /** 
41      * Kind-of error that occurred
42      */
43     private ErrType errType;
44 
45     /** 
46      * Constructs a new `EskomCalendarException` of the given
47      * kind-of error that occurred with an optional message
48      * which is emoty by default
49      *
50      * Params:
51      *   errType = the kind-of error
52      */
53     this(ErrType errType, string msg = "")
54     {
55         this.errType = errType;
56         super(to!(string)(errType)~(msg.length ? (": "~msg) : ""));
57     }
58 
59     /** 
60      * Gets the kind-of error that occurred
61      *
62      * Returns: the error as an `ErrType`
63      */
64     public ErrType getError()
65     {
66         return errType;
67     }
68 }