Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3637

Quarkus REST Streaming - How to return error when stream crashes?

$
0
0

i need to create a CSV-Export that streams data (not load it completely into memory):

    @GET    @Produces(MediaType.APPLICATION_OCTET_STREAM)    @Path("/export/csv")    public Response streamCsv() throws InvalidDataException {        final StreamingOutput streamingOutput =            os -> productManager.exportCsv(new RequestContext(1, 1), os);        return Response            .ok(streamingOutput, MediaType.APPLICATION_OCTET_STREAM)            .header("Content-Disposition", "attachment; filename=product_export.csv")            .build();    }

this works correctly,

but when the stream crashes (because of any type of error during the stream-processing) the endpoint will still return a HTTP Status-Code 200 (Success), and will not return an error to the caller (like HTTP Status-Code 500)

The caller will get the impression that the CSV-File is valid, but it may only contain as many lines until the error occured.

  • How can i write a streaming-endpoint in quarkus, that can return Error-Codes to the Caller to indicate if the streaming had an error ?

Note: it is important to note, that the full data should not! be loaded into memory at any time. It is allowed to load small chunks of data into memory. Therefore a solution that contains os.toByteArray() would not be sufficient.


Viewing all articles
Browse latest Browse all 3637

Trending Articles