From 4ad6c4bd0a35ebd903040dcd01f64331811c7fee Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 22 Mar 2025 10:43:31 +0100 Subject: [PATCH] feat: handle and save issue report for non HTTP 2xx responses --- .../dev/dnpm/etl/processor/output/RestMtbFileSender.kt | 6 ++++-- .../dev/dnpm/etl/processor/services/RequestProcessor.kt | 2 +- .../etl/processor/output/RestBwhcMtbFileSenderTest.kt | 8 ++++---- .../dnpm/etl/processor/output/RestDipMtbFileSenderTest.kt | 8 ++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt index b77611c..5ea42e3 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/output/RestMtbFileSender.kt @@ -28,6 +28,7 @@ import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.retry.support.RetryTemplate import org.springframework.web.client.RestClientException +import org.springframework.web.client.RestClientResponseException import org.springframework.web.client.RestTemplate abstract class RestMtbFileSender( @@ -64,9 +65,10 @@ abstract class RestMtbFileSender( } } catch (e: IllegalArgumentException) { logger.error("Not a valid URI to export to: '{}'", restTargetProperties.uri!!) - } catch (e: RestClientException) { + } catch (e: RestClientResponseException) { logger.info(restTargetProperties.uri!!.toString()) - logger.error("Cannot send data to remote system", e) + logger.error("Request data not accepted by remote system", e) + return MtbFileSender.Response(e.statusCode.asRequestStatus(), e.responseBodyAsString) } return MtbFileSender.Response(RequestStatus.ERROR, "Sonstiger Fehler bei der Übertragung") } diff --git a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt index f4e6222..5b2c42a 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/services/RequestProcessor.kt @@ -93,7 +93,7 @@ class RequestProcessor( Instant.now(), responseStatus.status, when (responseStatus.status) { - RequestStatus.WARNING -> Optional.of(responseStatus.body) + RequestStatus.ERROR, RequestStatus.WARNING -> Optional.of(responseStatus.body) else -> Optional.empty() } ) diff --git a/src/test/kotlin/dev/dnpm/etl/processor/output/RestBwhcMtbFileSenderTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/output/RestBwhcMtbFileSenderTest.kt index abd7f9d..5063a97 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/output/RestBwhcMtbFileSenderTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/output/RestBwhcMtbFileSenderTest.kt @@ -213,23 +213,23 @@ class RestBwhcMtbFileSenderTest { ), RequestWithResponse( HttpStatus.BAD_REQUEST, - "??", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ), RequestWithResponse( HttpStatus.UNPROCESSABLE_ENTITY, errorBody, - MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) + MtbFileSender.Response(RequestStatus.ERROR, errorBody) ), // Some more errors not mentioned in documentation RequestWithResponse( HttpStatus.NOT_FOUND, - "what????", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ), RequestWithResponse( HttpStatus.INTERNAL_SERVER_ERROR, - "what????", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ) ) diff --git a/src/test/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSenderTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSenderTest.kt index ed8c6f0..dac6496 100644 --- a/src/test/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSenderTest.kt +++ b/src/test/kotlin/dev/dnpm/etl/processor/output/RestDipMtbFileSenderTest.kt @@ -213,23 +213,23 @@ class RestDipMtbFileSenderTest { ), RequestWithResponse( HttpStatus.BAD_REQUEST, - "??", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ), RequestWithResponse( HttpStatus.UNPROCESSABLE_ENTITY, errorBody, - MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) + MtbFileSender.Response(RequestStatus.ERROR, errorBody) ), // Some more errors not mentioned in documentation RequestWithResponse( HttpStatus.NOT_FOUND, - "what????", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ), RequestWithResponse( HttpStatus.INTERNAL_SERVER_ERROR, - "what????", + ERROR_RESPONSE_BODY, MtbFileSender.Response(RequestStatus.ERROR, ERROR_RESPONSE_BODY) ) )