2 * Copyright 2017-2018 Gregory Moyer and contributors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.lametrictime.api.local;
18 import java.util.List;
20 import org.openhab.binding.lametrictime.api.local.model.Error;
21 import org.openhab.binding.lametrictime.api.local.model.Failure;
23 public class LaMetricTimeException extends Exception
25 private static final long serialVersionUID = 1L;
27 public LaMetricTimeException()
32 public LaMetricTimeException(String message)
37 public LaMetricTimeException(Throwable cause)
42 public LaMetricTimeException(String message, Throwable cause)
44 super(message, cause);
47 public LaMetricTimeException(String message,
49 boolean enableSuppression,
50 boolean writableStackTrace)
52 super(message, cause, enableSuppression, writableStackTrace);
55 public LaMetricTimeException(Failure failure)
57 super(buildMessage(failure));
60 private static String buildMessage(Failure failure)
62 StringBuilder builder = new StringBuilder();
64 List<Error> errors = failure.getErrors();
65 if (!errors.isEmpty())
67 builder.append(errors.get(0).getMessage());
70 for (int i = 1; i < errors.size(); i++)
72 builder.append("; ").append(errors.get(i).getMessage());
75 return builder.toString();