Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Improve Error Messages and Recovery Suggestions #44

Merged
2 commits merged into from
Feb 20, 2017
Merged

Improve Error Messages and Recovery Suggestions #44

2 commits merged into from
Feb 20, 2017

Conversation

ghost
Copy link

@ghost ghost commented Feb 20, 2017

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. This allows displaying of the error message and recovery suggestion to the user of github-scanner
  • 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

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
@ghost ghost requested review from arnau and jamaine-ustwo February 20, 2017 08:04
Copy link

@arnau arnau left a 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,
Copy link

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? {
Copy link

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
Copy link

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

Copy link
Author

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.

@ghost ghost merged commit 2847e89 into master Feb 20, 2017
@ghost ghost deleted the error-messages branch February 20, 2017 09:41
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant