001/** 002 * Copyright (C) 2006-2022 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 lombok.Getter; 019 020public class ComponentException extends RuntimeException { 021 022 public static enum ErrorOrigin { 023 USER, // Error caused by user misconfiguration 024 BACKEND, // Error caused by backend 025 UNKNOWN // Any other error 026 } 027 028 @Getter 029 private final ErrorOrigin errorOrigin; 030 031 @Getter 032 private final String originalType; 033 034 @Getter 035 private final String originalMessage; 036 037 public ComponentException(final ErrorOrigin errorOrigin, final String type, final String message, 038 final StackTraceElement[] stackTrace, final Throwable cause) { 039 super((type != null ? "(" + type + ") " : "") + message, cause); 040 this.errorOrigin = errorOrigin; 041 originalType = type; 042 originalMessage = message; 043 if (stackTrace != null) { 044 setStackTrace(stackTrace); 045 } 046 } 047 048 public ComponentException(final String type, final String message, final StackTraceElement[] stackTrace, 049 final Throwable cause) { 050 this(ErrorOrigin.UNKNOWN, type, message, stackTrace, cause); 051 } 052 053 public ComponentException(final ErrorOrigin errorOrigin, final String message) { 054 this(errorOrigin, message, null); 055 } 056 057 public ComponentException(final ErrorOrigin errorOrigin, final String message, final Throwable cause) { 058 this(errorOrigin, cause != null ? cause.getClass().getName() : null, message, null, cause); 059 } 060 061 public ComponentException(final String message) { 062 this(ErrorOrigin.UNKNOWN, message); 063 } 064 065 public ComponentException(final String message, final Throwable cause) { 066 this(ErrorOrigin.UNKNOWN, message, cause); 067 } 068 069 public ComponentException(final Throwable cause) { 070 this(ErrorOrigin.UNKNOWN, cause.getMessage(), cause); 071 } 072 073}