Skip to content

Commit

Permalink
Merge pull request #54 from ZekeSnider/zeke/webhook-logs
Browse files Browse the repository at this point in the history
Add more log statements for webhook events
  • Loading branch information
ZekeSnider authored Jul 27, 2021
2 parents 4d241b9 + aab2bd2 commit acfc17a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Jared/WebHookManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class WebHookManager: MessageDelegate, RoutingModule {
}

public func notifyRoute(_ message: Message, url: String) {
NSLog("Notifying \(url) of new message event")

guard let parsedUrl = URL(string: url) else {
NSLog("Unable to parse URL for webhook \(url)")
return
}
let webhookBody = WebHookManager.createWebhookBody(message)
Expand All @@ -54,6 +57,7 @@ class WebHookManager: MessageDelegate, RoutingModule {
urlSession.dataTask(with: request) { data, response, error in
guard error == nil, let data = data, let httpResponse = response as? HTTPURLResponse,
httpResponse.statusCode == 200 else {
NSLog("Received error while requesting webhook \(error.debugDescription)")
return
}
guard let decoded = try? JSONDecoder().decode(WebhookResponse.self, from: data) else {
Expand Down Expand Up @@ -91,6 +95,7 @@ class WebHookManager: MessageDelegate, RoutingModule {
})

self.routes = self.webhooks.flatMap({ $0.routes ?? [] })
NSLog("Webhooks updated to: \(self.webhooks.map{ $0.url }.joined(separator: ", "))")
}

static private func createWebhookBody(_ message: Message) -> Data? {
Expand Down

0 comments on commit acfc17a

Please sign in to comment.