Skip to content

Commit

Permalink
Merge pull request #20 from hmrc/APID-69
Browse files Browse the repository at this point in the history
APID-69: improve logging on notifications
  • Loading branch information
lburgos authored Jan 27, 2021
2 parents ada9319 + 73bb7fc commit 67e5553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<Envelope><Body>foobar</Body></Envelope>", now, now, Some("https://invalidUrl"))

val result: Option[Int] = await(underTest.sendNotification(message))

result shouldBe None
}
}
}

0 comments on commit 67e5553

Please sign in to comment.