use of tech.allegro.schema.json2avro.converter.AvroConversionException in project hermes by allegro.
the class FilteringService method verify.
public MessageFiltersVerificationResult verify(MessageFiltersVerificationInput verification, TopicName topicName) {
Topic topic = topicService.getTopicDetails(topicName);
CompiledSchema<Schema> avroSchema = getLatestAvroSchemaIfExists(topic);
byte[] messageContent;
try {
messageContent = getBytes(verification.getMessage(), topic, avroSchema);
} catch (AvroConversionException e) {
return new MessageFiltersVerificationResult(ERROR, createErrorMessage(e));
}
MessageForFiltersVerification message = new MessageForFiltersVerification(messageContent, topic.getContentType(), avroSchema);
FilterChain filterChain = filterChainFactory.create(verification.getFilters());
FilterResult result = filterChain.apply(message);
return toMessageFiltersVerificationResult(result);
}
use of tech.allegro.schema.json2avro.converter.AvroConversionException in project quick by bakdata.
the class AvroExceptionHandler method handle.
@Override
public HttpResponse<ErrorMessage> handle(final HttpRequest request, final AvroRuntimeException exception) {
final ErrorMessage errorMessage;
final String detail;
if (exception instanceof AvroTypeException || exception instanceof AvroMissingFieldException || exception instanceof UnresolvedUnionException) {
detail = String.format("Could not parse input: %s", exception.getMessage());
} else if (exception instanceof AvroConversionException) {
detail = String.format("An Error occurred during conversion of the Avro: %s", exception.getMessage());
} else {
errorMessage = HttpStatusError.toError(HttpStatus.INTERNAL_SERVER_ERROR, request.getPath(), exception.getMessage());
return HttpResponse.<ErrorMessage>status(HttpStatus.valueOf(errorMessage.getCode())).body(errorMessage);
}
errorMessage = HttpStatusError.toError(HttpStatus.BAD_REQUEST, request.getPath(), detail);
return HttpResponse.<ErrorMessage>status(HttpStatus.valueOf(errorMessage.getCode())).body(errorMessage);
}
Aggregations