]> git.basschouten.com Git - openhab-addons.git/blob
0ab36ed21d2162ca0803b25a46deea20b95be38a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.asuswrt.internal.helpers;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * This class is used for handling errors.
20  *
21  * @author Christian Wild - Initial contribution
22  */
23 @NonNullByDefault
24 public class AsuswrtErrorHandler {
25     private String errorMessage = "";
26     private String infoMessage = "";
27
28     public AsuswrtErrorHandler() {
29     }
30
31     public AsuswrtErrorHandler(Exception ex) {
32         raiseError(ex);
33     }
34
35     /*
36      * Public functions
37      */
38
39     /**
40      * Raises a new error.
41      *
42      * @param ex the exception
43      */
44     public void raiseError(Exception ex) {
45         raiseError(ex, "");
46     }
47
48     /**
49      * Raises a new error.
50      *
51      * @param ex the exception
52      * @param infoMessage optional info message
53      */
54     public void raiseError(Exception ex, @Nullable String infoMessage) {
55         this.errorMessage = AsuswrtUtils.getValueOrDefault(ex.getMessage(), "");
56         this.infoMessage = AsuswrtUtils.getValueOrDefault(infoMessage, "");
57     }
58
59     /**
60      * Raises a new error.
61      *
62      * @param errorMessage the error message
63      * @param infoMessage optional info message
64      */
65     public void raiseError(String errorMessage, @Nullable String infoMessage) {
66         this.errorMessage = errorMessage;
67         this.infoMessage = AsuswrtUtils.getValueOrDefault(infoMessage, "");
68     }
69
70     /**
71      * Resets the error.
72      */
73     public void reset() {
74         errorMessage = "";
75         infoMessage = "";
76     }
77
78     /*
79      * Getters
80      */
81
82     /**
83      * Get the error message.
84      */
85     public String getErrorMessage() {
86         return errorMessage;
87     }
88
89     /**
90      * Get the info message.
91      */
92     public String getInfoMessage() {
93         return infoMessage;
94     }
95 }