Search in sources :

Example 1 with AvroConversionException

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);
}
Also used : MessageFiltersVerificationResult(pl.allegro.tech.hermes.api.MessageFiltersVerificationResult) Schema(org.apache.avro.Schema) CompiledSchema(pl.allegro.tech.hermes.schema.CompiledSchema) FilterChain(pl.allegro.tech.hermes.domain.filtering.chain.FilterChain) AvroConversionException(tech.allegro.schema.json2avro.converter.AvroConversionException) FilterResult(pl.allegro.tech.hermes.domain.filtering.chain.FilterResult) Topic(pl.allegro.tech.hermes.api.Topic)

Example 2 with AvroConversionException

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);
}
Also used : AvroMissingFieldException(org.apache.avro.AvroMissingFieldException) AvroConversionException(tech.allegro.schema.json2avro.converter.AvroConversionException) ErrorMessage(com.bakdata.quick.common.api.model.ErrorMessage) UnresolvedUnionException(org.apache.avro.UnresolvedUnionException) AvroTypeException(org.apache.avro.AvroTypeException)

Aggregations

AvroConversionException (tech.allegro.schema.json2avro.converter.AvroConversionException)2 ErrorMessage (com.bakdata.quick.common.api.model.ErrorMessage)1 AvroMissingFieldException (org.apache.avro.AvroMissingFieldException)1 AvroTypeException (org.apache.avro.AvroTypeException)1 Schema (org.apache.avro.Schema)1 UnresolvedUnionException (org.apache.avro.UnresolvedUnionException)1 MessageFiltersVerificationResult (pl.allegro.tech.hermes.api.MessageFiltersVerificationResult)1 Topic (pl.allegro.tech.hermes.api.Topic)1 FilterChain (pl.allegro.tech.hermes.domain.filtering.chain.FilterChain)1 FilterResult (pl.allegro.tech.hermes.domain.filtering.chain.FilterResult)1 CompiledSchema (pl.allegro.tech.hermes.schema.CompiledSchema)1