Skip to content

Commit

Permalink
APID-69: improve logging on notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgos committed Jan 27, 2021
1 parent ada9319 commit 73bb7fc
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 73bb7fc

Please sign in to comment.