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.lametrictime.internal.api.local;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lametrictime.internal.api.local.dto.Error;
19 import org.openhab.binding.lametrictime.internal.api.local.dto.Failure;
22 * Parent class for LaMetricTime exceptions.
24 * @author Gregory Moyer - Initial contribution
27 public class LaMetricTimeException extends Exception {
28 private static final long serialVersionUID = 1L;
30 public LaMetricTimeException() {
34 public LaMetricTimeException(String message) {
38 public LaMetricTimeException(Throwable cause) {
42 public LaMetricTimeException(String message, Throwable cause) {
43 super(message, cause);
46 public LaMetricTimeException(String message, Throwable cause, boolean enableSuppression,
47 boolean writableStackTrace) {
48 super(message, cause, enableSuppression, writableStackTrace);
51 public LaMetricTimeException(Failure failure) {
52 super(buildMessage(failure));
55 private static String buildMessage(Failure failure) {
56 StringBuilder builder = new StringBuilder();
58 List<Error> errors = failure.getErrors();
59 if (!errors.isEmpty()) {
60 builder.append(errors.get(0).getMessage());
63 for (int i = 1; i < errors.size(); i++) {
64 builder.append("; ").append(errors.get(i).getMessage());
67 return builder.toString();