2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.netatmo.internal.api;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.ServiceError;
22 * An exception that occurred while communicating with Netatmo server or related processes.
24 * @author Gaƫl L'hopital - Initial contribution
27 public class NetatmoException extends IOException {
28 private static final long serialVersionUID = 1513549973502021727L;
29 private ServiceError statusCode = ServiceError.UNKNOWN;
31 public NetatmoException(String format, Object... args) {
32 super(String.format(format, args));
35 public NetatmoException(Exception e, String format, Object... args) {
36 super(String.format(format, args), e);
39 public NetatmoException(String message) {
43 public NetatmoException(ApiError error) {
44 super(error.getMessage());
45 this.statusCode = error.getCode();
48 public ServiceError getStatusCode() {
53 public @Nullable String getMessage() {
54 String message = super.getMessage();
55 return message == null ? null
56 : ServiceError.UNKNOWN.equals(statusCode) ? message
57 : String.format("Rest call failed: statusCode=%s, message=%s", statusCode, message);