Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

node not being parsed if there is an error #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Sources/VaporAPNS/VaporAPNS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ open class VaporAPNS {

if responseData != "" {
// Get JSON from loaded data string
let jsonNode = JSON(.bytes(responseData.makeBytes()), in: nil).makeNode(in: nil)
if let reason = jsonNode["reason"]?.string {
result = Result.error(apnsId: message.messageId, deviceToken: deviceToken, error: APNSError.init(errorReason: reason))
} else {
result = Result.success(apnsId: message.messageId, deviceToken: deviceToken, serviceStatus: .success)
do {
let jsonNode = try JSON(bytes: responseData.makeBytes()).makeNode(in: nil)
if let reason = jsonNode["reason"]?.string {
result = Result.error(apnsId: message.messageId, deviceToken: deviceToken, error: APNSError.init(errorReason: reason))
} else {
result = Result.success(apnsId: message.messageId, deviceToken: deviceToken, serviceStatus: .success)
}
} catch let e {
result = Result.error(apnsId: message.messageId, deviceToken: deviceToken, error: APNSError.init(errorReason: e.localizedDescription))
}
} else {
result = Result.success(apnsId: message.messageId, deviceToken: deviceToken, serviceStatus: .success)
Expand Down