Skip to content

Commit

Permalink
Merge pull request #2 from vapor-community/HotFix
Browse files Browse the repository at this point in the history
Added better error handling.
  • Loading branch information
Andrewangeta authored Sep 2, 2017
2 parents fa9ff5f + 727ee26 commit 10ae04a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Sources/Telesign/API/TelesignRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ public final class TelesignRequest<T: TelesignResponse>
{
guard self.response.status.statusCode <= 299 else
{
throw TelesignError.connectionError(self.response.status)
guard let message = response.json?["status"]?["description"]?.string,
let code = response.json?["status"]?["code"]?.int
else
{
throw self.response.status
}

throw TelesignError.connectionError(message, code)
}

guard let value = self.response.json else { throw TelesignError.malformedEncodedBody }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telesign/Errors/TelesignError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum TelesignError: Error

case malformedEncodedBody

case connectionError(Status)
case connectionError(String,Int)

var localizedDescription: String
{
Expand All @@ -33,7 +33,7 @@ public enum TelesignError: Error

case .malformedEncodedBody: return "Got a malformed encoded body. Check your encoded values."

case .connectionError(let status): return "\(status.reasonPhrase)"
case .connectionError(let description, let code): return "Error code \(code). \(description)"
}
}
}

0 comments on commit 10ae04a

Please sign in to comment.