]> git.basschouten.com Git - openhab-addons.git/blob
0038c08721d3b4be39a412bb8fc5e822ff828101
[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.solaredge.internal.connector;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.jetty.http.HttpStatus.Code;
18
19 /**
20  * this class contains the HTTP status of the communication and an optional exception that might occoured during
21  * communication
22  *
23  * @author Alexander Friese - initial contribution
24  */
25 @NonNullByDefault
26 public class CommunicationStatus {
27
28     private @Nullable Code httpCode;
29     private @Nullable Exception error;
30
31     public final Code getHttpCode() {
32         Code httpCode = this.httpCode;
33         return httpCode == null ? Code.INTERNAL_SERVER_ERROR : httpCode;
34     }
35
36     public final void setHttpCode(Code httpCode) {
37         this.httpCode = httpCode;
38     }
39
40     public final @Nullable Exception getError() {
41         return error;
42     }
43
44     public final void setError(Exception error) {
45         this.error = error;
46     }
47
48     public final String getMessage() {
49         Code httpCode = this.httpCode;
50         Exception error = this.error;
51         if (error != null) {
52             String message = error.getMessage();
53             if (message != null && !message.isEmpty()) {
54                 return message;
55             }
56         } else if (httpCode != null && httpCode.getMessage() != null && !httpCode.getMessage().isEmpty()) {
57             return httpCode.getMessage();
58         }
59         return "";
60     }
61 }