diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnector.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnector.scala index 9b0fc88..de92135 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnector.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnector.scala @@ -35,10 +35,12 @@ class NotificationCallbackConnector @Inject()(httpClient: HttpClient) def sendNotification(message: OutboundSoapMessage)(implicit hc: HeaderCarrier): Future[Option[Int]] = { (message.notificationUrl map { url => httpClient.POST[SoapMessageStatus, HttpResponse](url, SoapMessageStatus(message.globalId, message.messageId, message.status)) map { response => - if (!is2xx(response.status)) { - logger.warn(s"Attempted request to $url responded with HTTP response code ${response.status}") - } + logger.info(s"Notification to $url with global ID ${message.globalId} and message ID ${message.messageId} responded with HTTP code ${response.status}") Some(response.status) + } recover { + case e: Exception => + logger.error(s"Notification to $url with global ID ${message.globalId} and message ID ${message.messageId} failed: ${e.getMessage}", e) + None } }).getOrElse(successful(None)) } diff --git a/it/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnectorISpec.scala b/it/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnectorISpec.scala index 3ca2a43..bc0ad61 100644 --- a/it/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnectorISpec.scala +++ b/it/uk/gov/hmrc/apiplatformoutboundsoap/connectors/NotificationCallbackConnectorISpec.scala @@ -103,5 +103,14 @@ class NotificationCallbackConnectorISpec extends AnyWordSpec with Matchers with result shouldBe expectedStatus } + + "recover from exceptions" in new Setup { + val message: OutboundSoapMessage = RetryingOutboundSoapMessage( + globalId, messageId, "foobar", now, now, Some("https://invalidUrl")) + + val result: Option[Int] = await(underTest.sendNotification(message)) + + result shouldBe None + } } }