From 81a56c9b88196e6861e4201163dee8d5c0a5aa54 Mon Sep 17 00:00:00 2001 From: Josh Sklar Date: Wed, 10 May 2017 15:52:59 -0400 Subject: [PATCH 1/5] add httpResponse to RequestError --- Source/Siesta/RequestError.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Siesta/RequestError.swift b/Source/Siesta/RequestError.swift index 76f2bd33..5a2fcada 100644 --- a/Source/Siesta/RequestError.swift +++ b/Source/Siesta/RequestError.swift @@ -38,8 +38,15 @@ public struct RequestError: Error */ public var userMessage: String + /// The HTTP response if this error came from an HTTP response. + public var httpResponse: HTTPURLResponse? + /// The HTTP status code (e.g. 404) if this error came from an HTTP response. - public var httpStatusCode: Int? + public var httpStatusCode: Int? { + get { + return httpResponse?.statusCode + } + } /// The response body if this error came from an HTTP response. Its meaning is API-specific. public var entity: Entity? @@ -63,7 +70,7 @@ public struct RequestError: Error cause: Error?, userMessage: String? = nil) { - self.httpStatusCode = response?.statusCode + self.httpResponse = response self.cause = cause if let content = content @@ -73,7 +80,7 @@ public struct RequestError: Error { self.userMessage = message } else if let message = cause?.localizedDescription { self.userMessage = message } - else if let code = self.httpStatusCode + else if let code = self.httpResponse?.statusCode { self.userMessage = HTTPURLResponse.localizedString(forStatusCode: code).capitalized } else { self.userMessage = NSLocalizedString("Request failed", comment: "userMessage") } // Is this reachable? From 38e68efd9f611085ebbc60a7f4766b2f3afab0f9 Mon Sep 17 00:00:00 2001 From: Josh Sklar Date: Wed, 10 May 2017 19:15:50 -0400 Subject: [PATCH 2/5] make httpResponse a let --- Source/Siesta/RequestError.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Siesta/RequestError.swift b/Source/Siesta/RequestError.swift index 5a2fcada..ffa295dd 100644 --- a/Source/Siesta/RequestError.swift +++ b/Source/Siesta/RequestError.swift @@ -39,7 +39,7 @@ public struct RequestError: Error public var userMessage: String /// The HTTP response if this error came from an HTTP response. - public var httpResponse: HTTPURLResponse? + public let httpResponse: HTTPURLResponse? /// The HTTP status code (e.g. 404) if this error came from an HTTP response. public var httpStatusCode: Int? { @@ -94,6 +94,7 @@ public struct RequestError: Error cause: Error, entity: Entity? = nil) { + self.httpResponse = nil self.userMessage = userMessage self.cause = cause self.entity = entity From edb56ac8dfcb75acb4b756df85e91b896de1c75c Mon Sep 17 00:00:00 2001 From: Josh Sklar Date: Sun, 14 May 2017 22:54:36 -0400 Subject: [PATCH 3/5] Revert "make httpResponse a let" This reverts commit 38e68efd9f611085ebbc60a7f4766b2f3afab0f9. --- Source/Siesta/RequestError.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Siesta/RequestError.swift b/Source/Siesta/RequestError.swift index ffa295dd..5a2fcada 100644 --- a/Source/Siesta/RequestError.swift +++ b/Source/Siesta/RequestError.swift @@ -39,7 +39,7 @@ public struct RequestError: Error public var userMessage: String /// The HTTP response if this error came from an HTTP response. - public let httpResponse: HTTPURLResponse? + public var httpResponse: HTTPURLResponse? /// The HTTP status code (e.g. 404) if this error came from an HTTP response. public var httpStatusCode: Int? { @@ -94,7 +94,6 @@ public struct RequestError: Error cause: Error, entity: Entity? = nil) { - self.httpResponse = nil self.userMessage = userMessage self.cause = cause self.entity = entity From ef698690dd3401723e863973599a2c20be49c280 Mon Sep 17 00:00:00 2001 From: Josh Sklar Date: Sun, 14 May 2017 22:54:55 -0400 Subject: [PATCH 4/5] Revert "add httpResponse to RequestError" This reverts commit 81a56c9b88196e6861e4201163dee8d5c0a5aa54. --- Source/Siesta/RequestError.swift | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Source/Siesta/RequestError.swift b/Source/Siesta/RequestError.swift index 5a2fcada..76f2bd33 100644 --- a/Source/Siesta/RequestError.swift +++ b/Source/Siesta/RequestError.swift @@ -38,15 +38,8 @@ public struct RequestError: Error */ public var userMessage: String - /// The HTTP response if this error came from an HTTP response. - public var httpResponse: HTTPURLResponse? - /// The HTTP status code (e.g. 404) if this error came from an HTTP response. - public var httpStatusCode: Int? { - get { - return httpResponse?.statusCode - } - } + public var httpStatusCode: Int? /// The response body if this error came from an HTTP response. Its meaning is API-specific. public var entity: Entity? @@ -70,7 +63,7 @@ public struct RequestError: Error cause: Error?, userMessage: String? = nil) { - self.httpResponse = response + self.httpStatusCode = response?.statusCode self.cause = cause if let content = content @@ -80,7 +73,7 @@ public struct RequestError: Error { self.userMessage = message } else if let message = cause?.localizedDescription { self.userMessage = message } - else if let code = self.httpResponse?.statusCode + else if let code = self.httpStatusCode { self.userMessage = HTTPURLResponse.localizedString(forStatusCode: code).capitalized } else { self.userMessage = NSLocalizedString("Request failed", comment: "userMessage") } // Is this reachable? From c22b6b89880ef950a14a7c33fd2a21d79ed85760 Mon Sep 17 00:00:00 2001 From: Josh Sklar Date: Sun, 14 May 2017 22:59:23 -0400 Subject: [PATCH 5/5] add url property --- Source/Siesta/RequestError.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Siesta/RequestError.swift b/Source/Siesta/RequestError.swift index 76f2bd33..1174f972 100644 --- a/Source/Siesta/RequestError.swift +++ b/Source/Siesta/RequestError.swift @@ -40,6 +40,9 @@ public struct RequestError: Error /// The HTTP status code (e.g. 404) if this error came from an HTTP response. public var httpStatusCode: Int? + + /// The URL for the request that this error represents. + public var url: URL? /// The response body if this error came from an HTTP response. Its meaning is API-specific. public var entity: Entity? @@ -64,6 +67,7 @@ public struct RequestError: Error userMessage: String? = nil) { self.httpStatusCode = response?.statusCode + self.url = response?.url self.cause = cause if let content = content