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.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 enum ErrorType {
37 SERVICE_UNABLE_TO_START,
43 private final ErrorType cause;
45 public VolvoOnCallException(String label, @Nullable String description) {
47 if ("FoundationServicesUnavailable".equalsIgnoreCase(label)) {
48 cause = ErrorType.SERVICE_UNAVAILABLE;
49 } else if ("ServiceUnableToStart".equalsIgnoreCase(label)) {
50 cause = ErrorType.SERVICE_UNABLE_TO_START;
52 cause = ErrorType.UNKNOWN;
53 logger.warn("Unhandled VoC error : {} : {}", label, description);
57 public VolvoOnCallException(Exception e) {
59 if (e instanceof IOException) {
60 cause = ErrorType.IOEXCEPTION;
61 } else if (e instanceof JsonSyntaxException) {
62 cause = ErrorType.JSON_SYNTAX;
63 } else if (e instanceof InterruptedException) {
64 cause = ErrorType.INTERRUPTED;
66 cause = ErrorType.UNKNOWN;
67 logger.warn("Unhandled VoC error : {}", e.getMessage());
71 public ErrorType getType() {