001/**
002 * Copyright (C) 2006-2024 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.api.exception;
017
018import javax.json.bind.annotation.JsonbCreator;
019
020import lombok.Data;
021
022/**
023 * This class is dedicated to Studio's guess schema feature.
024 * It has the same goal as ComponentException except that you can specify an action to execute in some cases.
025 *
026 * If you don't need such feature, just use ComponentException.
027 *
028 * See me TCOMP-2342 for more details.
029 */
030@Data
031public class DiscoverSchemaException extends RuntimeException {
032
033    public enum HandleErrorWith {
034        EXCEPTION,
035        SILENT,
036        RETRY,
037        EXECUTE_MOCK_JOB;
038    }
039
040    private HandleErrorWith possibleHandleErrorWith = HandleErrorWith.EXCEPTION;
041
042    public DiscoverSchemaException(final ComponentException e) {
043        super(e.getOriginalMessage(), e.getCause());
044    }
045
046    public DiscoverSchemaException(final ComponentException e, final HandleErrorWith handling) {
047        super(e.getOriginalMessage(), e.getCause());
048        setPossibleHandleErrorWith(handling);
049    }
050
051    public DiscoverSchemaException(final String message, final HandleErrorWith handling) {
052        super(message);
053        setPossibleHandleErrorWith(handling);
054    }
055
056    @JsonbCreator
057    public DiscoverSchemaException(final String message, final StackTraceElement[] stackTrace,
058            final HandleErrorWith handling) {
059        super(message);
060        setStackTrace(stackTrace);
061        setPossibleHandleErrorWith(handling);
062    }
063
064}