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