2 * Copyright (c) 2010-2020 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.volvooncall.internal;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.google.gson.JsonSyntaxException;
25 * Exception for errors when using the VolvoOnCall API
27 * @author Gaƫl L'hopital - Initial contribution
30 public class VolvoOnCallException extends Exception {
31 private final Logger logger = LoggerFactory.getLogger(VolvoOnCallException.class);
32 private static final long serialVersionUID = -6215621577081394328L;
34 public static enum ErrorType {
41 private final ErrorType cause;
43 public VolvoOnCallException(String label, @Nullable String description) {
45 if ("FoundationServicesUnavailable".equalsIgnoreCase(label)) {
46 cause = ErrorType.SERVICE_UNAVAILABLE;
48 cause = ErrorType.UNKNOWN;
49 logger.warn("Unhandled VoC error : {} : {}", label, description);
53 public VolvoOnCallException(Exception e) {
55 if (e instanceof IOException) {
56 cause = ErrorType.IOEXCEPTION;
57 } else if (e instanceof JsonSyntaxException) {
58 cause = ErrorType.JSON_SYNTAX;
60 cause = ErrorType.UNKNOWN;
61 logger.warn("Unhandled VoC error : {}", e.getMessage());
65 public ErrorType getType() {