-
Notifications
You must be signed in to change notification settings - Fork 3
Improve Error Messages and Recovery Suggestions #44
Conversation
Resolves #35 `Improve Error Explanation for Rate Limit`. - Adds checks for rate limiting and uses new, specific error - Refactors response validation to static methods in an extension of `ResponseHandler`, thus providing a default implementation to all response handlers - Refactors the deserialisation of JSON in `JSONResponseHandler` into a separate method to improve readability - Updates `GitHubScannerProtocolError` to inherit from `LocalizedError` and provides a default implementation for `CustomStringConvertible` - Adds `errorDescription` and `recoverySuggestion` to all error types - Moves `NetworkError` and `ScanOptionsError` into own files - Expands test suite for error handling - Refactors accessing the `HTTPURLResponse` next link header into an extension property to improve readability of `JSONResponseHandler` and to help maintain single responsibility principle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the minor style comment, everything looks good to me.
case .unauthorized: | ||
return "Not authorized" | ||
case let .unknown(error): | ||
if let localError = error as? LocalizedError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if
indentation looks a bit off.
} | ||
} | ||
|
||
public var recoverySuggestion: String? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful
/// - Parameter response: The `HTTPURLResponse` to validate. | ||
/// - Returns: Whether or not the response is valid. | ||
public static func isValidResponseStatus(_ response: HTTPURLResponse) -> Bool { | ||
return 200..<300 ~= response.statusCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3xx range is valid as well. Perhaps in a future iteration you should handle at least a few of them (i.e. 301, 302 and 307) https://developer.github.com/v3/#http-redirects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Issue #45 Handle HTTP Redirects
.
Per code review by @arnau
Resolves #35
Improve Error Explanation for Rate Limit
.ResponseHandler
, thus providing a default implementation to all response handlersJSONResponseHandler
into a separate method to improve readabilityGitHubScannerProtocolError
to inherit fromLocalizedError
and provides a default implementation forCustomStringConvertible
. This allows displaying of the error message and recovery suggestion to the user ofgithub-scanner
errorDescription
andrecoverySuggestion
to all error typesNetworkError
andScanOptionsError
into own filesHTTPURLResponse
next link header into an extension property to improve readability ofJSONResponseHandler
and to help maintain single responsibility principle