]> git.basschouten.com Git - openhab-addons.git/blob
c95dbfed90bf4f5bd9b8dbe27e01d9e5fd36fcfb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.openuv.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * Will be thrown for cloud errors
19  *
20  * @author GaĆ«l L'hopital - Initial contribution
21  */
22 @NonNullByDefault
23 public class OpenUVException extends Exception {
24     private static final long serialVersionUID = -1411477662081482350L;
25     private static final String ERROR_QUOTA_EXCEEDED = "Daily API quota exceeded";
26     private static final String ERROR_WRONG_KEY = "User with API Key not found";
27
28     public OpenUVException(String message) {
29         super(message);
30     }
31
32     public OpenUVException(String fitzPatrickIndex, Throwable e) {
33         super("Unexpected Fitzpatrick index value '%s'".formatted(fitzPatrickIndex), e);
34     }
35
36     private boolean checkMatches(String message) {
37         String currentMessage = getMessage();
38         return currentMessage != null && currentMessage.startsWith(message);
39     }
40
41     public boolean isApiKeyError() {
42         return checkMatches(ERROR_WRONG_KEY);
43     }
44
45     public boolean isQuotaError() {
46         return checkMatches(ERROR_QUOTA_EXCEEDED);
47     }
48 }