]> git.basschouten.com Git - openhab-addons.git/blob
8a3642fa234b3bffbc77f920d3b224e8388af776
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.nibeuplink.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 code = httpCode;
33         return code == null ? Code.INTERNAL_SERVER_ERROR : code;
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         Exception err = error;
50         String errMsg = err == null ? null : err.getMessage();
51         String msg = getHttpCode().getMessage();
52         if (errMsg != null && !errMsg.isEmpty()) {
53             return errMsg;
54         } else if (msg != null && !msg.isEmpty()) {
55             return msg;
56         }
57         return "";
58     }
59 }