本文整理汇总了Java中org.talend.daikon.exception.error.ErrorCode类的典型用法代码示例。如果您正苦于以下问题:Java ErrorCode类的具体用法?Java ErrorCode怎么用?Java ErrorCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorCode类属于org.talend.daikon.exception.error包,在下文中一共展示了ErrorCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeserialize
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void testDeserialize() throws IOException {
// check that the CodeError serialization can be deserialized into an JsonCodeError
TalendRuntimeException talendRuntimeException = new TalendRuntimeException(CommonErrorCodes.MISSING_I18N_TRANSLATOR,
ExceptionContext.build().put("key", "the key").put("baseName", "the baseName"));
StringWriter writer = new StringWriter();
talendRuntimeException.writeTo(writer);
ObjectMapper objectMapper = new ObjectMapper();
JsonErrorCode deserializedCode = objectMapper.reader(JsonErrorCode.class).readValue(writer.toString());
ErrorCode expectedCode = talendRuntimeException.getCode();
assertEquals(expectedCode.getCode(), deserializedCode.getCode());
assertEquals(expectedCode.getGroup(), deserializedCode.getGroup());
assertEquals(expectedCode.getProduct(), deserializedCode.getProduct());
assertThat(expectedCode.getExpectedContextEntries(),
containsInAnyOrder(deserializedCode.getExpectedContextEntries().toArray()));
assertThat(talendRuntimeException.getContext().entries(),
containsInAnyOrder(deserializedCode.getContext().entrySet().toArray()));
}
示例2: errorCodeConverter
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Bean
public Converter<String, ErrorCode> errorCodeConverter() {
// Don't convert to lambda -> cause issue for Spring to infer source and target types.
return new Converter<String, ErrorCode>() {
@Override
public ErrorCode convert(String source) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readerFor(JsonErrorCode.class).readValue(source);
} catch (Exception e) {
LOGGER.trace("Unable to read error code from '{}'", source, e);
// Build a JSON error code out of "source" (mostly likely a error code as string).
final ErrorCodeDto errorCodeDto = new ErrorCodeDto();
errorCodeDto.setCode(source);
errorCodeDto.setHttpStatus(CommonErrorCodes.UNEXPECTED_EXCEPTION.getHttpStatus());
errorCodeDto.setGroup(CommonErrorCodes.UNEXPECTED_EXCEPTION.getGroup());
errorCodeDto.setProduct(CommonErrorCodes.UNEXPECTED_EXCEPTION.getProduct());
return errorCodeDto;
}
}
};
}
示例3: TalendRuntimeException
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* @param code the error code, uniquely describing the error condition that occurred.
* @param cause the root cause of this error.
* @param context the context of the error when it occurred (used to detail the user error message in frontend).
*/
public TalendRuntimeException(ErrorCode code, Throwable cause, ExceptionContext context) {
super(code.getCode() + (context != null ? ":" + context.toString() : ""), cause); //$NON-NLS-1$ //$NON-NLS-2$
this.code = code;
this.cause = cause;
this.context = (context == null ? ExceptionContext.build() : context);
checkContext();
}
示例4: buildUnexpectedErrorResponse
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
private static ResponseEntity<ApiError> buildUnexpectedErrorResponse(ErrorCode code, String message, Throwable cause) {
ApiError dto = new ApiError();
dto.setCode(code.getProduct() + "_" + code.getGroup() + "_" + code.getCode());
dto.setMessage(message);
dto.setMessageTitle("An unexpected error occurred");
dto.setCause(cause == null ? null : cause.getMessage());
return new ResponseEntity<>(dto, HttpStatus.valueOf(code.getHttpStatus()));
}
示例5: rethrowOrWrap
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* If the exception is a TDPException, rethrow it, else wrap it and then throw it.
*
* @param throwable The throwable to rethrow or wrap in a TDPException.
* @param errorCode The Error code to use when you wrap the throwable.
*/
public static RuntimeException rethrowOrWrap(Throwable throwable, ErrorCode errorCode) {
if (throwable instanceof TDPException) {
throw (TDPException) throwable;
} else if (throwable instanceof HystrixRuntimeException) {
throw TDPExceptionUtils.processHystrixException((HystrixRuntimeException) throwable);
} else if (throwable.getCause() instanceof TDPException) {
throw (TDPException) (throwable.getCause());
} else {
throw new TDPException(errorCode, throwable);
}
}
示例6: TDPException
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* Build a Talend exception with no i18n handling internally. It is useful when the goal is to just pass an exception in a
* component
* that does not have access to the exception bundle.
*/
public TDPException(ErrorCode code, Throwable cause, String message, String messageTitle, ExceptionContext context) {
super(code, cause, context);
this.message = message;
this.messageTitle = messageTitle;
// Translation done at the object creation
List<Object> values = getValuesFromContext(context);
this.localizedMessage = ErrorMessage.getMessage(getCode(), values.toArray(new Object[values.size()]));
}
示例7: toExceptionDto
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
private static TdpExceptionDto toExceptionDto(TalendRuntimeException internal) {
ErrorCode errorCode = internal.getCode();
String serializedCode = errorCode.getProduct() + '_' + errorCode.getGroup() + '_' + errorCode.getCode();
String defaultMessage = internal.getMessage();
String message = internal.getLocalizedMessage();
String messageTitle = internal instanceof TDPException ? ((TDPException) internal).getMessageTitle() : null;
TdpExceptionDto cause =
internal.getCause() instanceof TDPException ? toExceptionDto((TDPException) internal.getCause()) : null;
Map<String, Object> context = new HashMap<>();
for (Map.Entry<String, Object> contextEntry : internal.getContext().entries()) {
context.put(contextEntry.getKey(), contextEntry.getValue());
}
return new TdpExceptionDto(serializedCode, cause, defaultMessage, message, messageTitle, context);
}
示例8: getMessagePrefix
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* Returns the prefix message according to the specified error code.
*
* @param errorCode the specified error code
* @return the prefix message according to the specified error code
*/
private static String getMessagePrefix(ErrorCode errorCode) {
switch (errorCode.getHttpStatus()) {
case 0:
return "SERVICE_UNAVAILABLE";
case 500:
return "GENERIC_ERROR";
default:
String code = errorCode.getCode();
return StringUtils.isNotEmpty(code) ? code : "GENERIC_ERROR";
}
}
示例9: JsonErrorCodeDescription
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* Copy constructor.
*
* @param copy the error code to copy.
*/
public JsonErrorCodeDescription(ErrorCode copy) {
this.product = copy.getProduct();
this.group = copy.getGroup();
this.code = copy.getCode();
this.httpStatus = copy.getHttpStatus();
this.expectedContextEntries = copy.getExpectedContextEntries();
}
示例10: getMessagePrefix
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
/**
* Returns the prefix message according to the specified error code.
*
* @param errorCode the specified error code
* @return the prefix message according to the specified error code
*/
private static String getMessagePrefix(ErrorCode errorCode) {
switch (errorCode.getHttpStatus()) {
case 0:
return "SERVICE_UNAVAILABLE";
case 500:
return "GENERIC_ERROR";
default:
String code = errorCode.getCode();
return StringUtils.isNotBlank(code) ? code : "GENERIC_ERROR";
}
}
示例11: shouldReturnRightErrorMessageWhenHttpStatusIsZero
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIsZero() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 0;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("Service unavailable", exception.getMessage());
assertEquals("An error has occurred", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
示例12: shouldReturnRightErrorMessageWhenHttpStatusIs500
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void shouldReturnRightErrorMessageWhenHttpStatusIs500() {
// given
ErrorCode errorCode = new ErrorCode() {
@Override
public String getProduct() {
return "TDP";
}
@Override
public String getGroup() {
return "API";
}
@Override
public int getHttpStatus() {
return 500;
}
@Override
public Collection<String> getExpectedContextEntries() {
return Collections.emptyList();
}
@Override
public String getCode() {
return null;
}
};
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("An unexpected error occurred and we could not complete your last operation. You can continue to use Data Preparation", exception.getMessage());
assertEquals("An error has occurred", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
示例13: shouldReturnRightErrorMessageWhenUnsupportedContentThrown
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void shouldReturnRightErrorMessageWhenUnsupportedContentThrown() {
// given
ErrorCode errorCode = UNSUPPORTED_CONTENT;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("Unable to create dataset, content is not supported. Try with a csv or xls file!", exception.getMessage());
assertEquals("Unsupported content", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
示例14: shouldReturnRightErrorMessageWhenDatasetStillInUseThrown
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void shouldReturnRightErrorMessageWhenDatasetStillInUseThrown() {
// given
ErrorCode errorCode = DATASET_STILL_IN_USE;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("You cannot delete the dataset, it is being used by preparation(s)", exception.getMessage());
assertEquals("Deletion forbidden", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}
示例15: shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown
import org.talend.daikon.exception.error.ErrorCode; //导入依赖的package包/类
@Test
public void shouldReturnRightErrorMessageWhenPreparationStepCannotBeDeletedInSingleModeThrown() {
// given
ErrorCode errorCode = PREPARATION_STEP_CANNOT_BE_DELETED_IN_SINGLE_MODE;
// when
TDPException exception = new TDPException(errorCode, null, null);
// then
assertEquals(errorCode, exception.getCode());
assertEquals("This action cannot be deleted because subsequent actions depend on it", exception.getMessage());
assertEquals("Delete action not authorized", exception.getMessageTitle());
assertFalse(exception.getContext().entries().iterator().hasNext());
}