]> git.basschouten.com Git - openhab-addons.git/blob
be4677da104b9ca57602dac22a5c26af9b9b3cd1
[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.automower.internal.rest.exceptions;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * An exception that occurred while communicating with an automower or an automower bridge
22  *
23  * @author Markus Pfleger - Initial contribution
24  */
25 @NonNullByDefault
26 public class AutomowerCommunicationException extends IOException {
27     private static final long serialVersionUID = 1L;
28     private int statusCode = -1;
29
30     public AutomowerCommunicationException(Exception e) {
31         super(e);
32     }
33
34     public AutomowerCommunicationException(int statusCode, Exception e) {
35         super(e);
36         this.statusCode = statusCode;
37     }
38
39     public AutomowerCommunicationException(int statusCode) {
40         this.statusCode = statusCode;
41     }
42
43     public AutomowerCommunicationException(int statusCode, String message) {
44         super(message);
45         this.statusCode = statusCode;
46     }
47
48     public AutomowerCommunicationException(String message, Exception e) {
49         super(message, e);
50     }
51
52     public AutomowerCommunicationException(String message) {
53         super(message);
54     }
55
56     public int getStatusCode() {
57         return statusCode;
58     }
59
60     @Override
61     public @Nullable String getMessage() {
62         String message = super.getMessage();
63         return message == null ? null : "Rest call failed: statusCode=" + statusCode + ", message=" + message;
64     }
65
66     @Override
67     public String toString() {
68         return getClass().getSimpleName() + ": statusCode=" + statusCode + ", message=" + super.getMessage()
69                 + ", cause: " + getCause();
70     }
71 }