-
Notifications
You must be signed in to change notification settings - Fork 55
Add SPIs for throwing RuntimeError from shorthand generated APIs #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,10 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret | |
| case transportFailed(any Error) | ||
| case handlerFailed(any Error) | ||
|
|
||
| // Unexpected response (thrown by shorthand APIs) | ||
| case unexpectedResponseStatus(expectedStatus: String, response: Any) | ||
| case unexpectedResponseBody(expectedContent: String, body: Any) | ||
|
|
||
| // MARK: CustomStringConvertible | ||
|
|
||
| var description: String { | ||
|
|
@@ -96,6 +100,20 @@ internal enum RuntimeError: Error, CustomStringConvertible, LocalizedError, Pret | |
| return "Transport failed with error: \(underlyingError.localizedDescription)" | ||
| case .handlerFailed(let underlyingError): | ||
| return "User handler failed with error: \(underlyingError.localizedDescription)" | ||
| case .unexpectedResponseStatus(let expectedStatus, let response): | ||
| return "Unexpected response, expected status code: \(expectedStatus), response: \(response)" | ||
| case .unexpectedResponseBody(let expectedContentType, let response): | ||
| return "Unexpected response body, expected content type: \(expectedContentType), response: \(response)" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @_spi(Generated) | ||
| public func throwUnexpectedResponseStatus(expectedStatus: String, response: Any) throws -> Never { | ||
| throw RuntimeError.unexpectedResponseStatus(expectedStatus: expectedStatus, response: response) | ||
| } | ||
|
|
||
| @_spi(Generated) | ||
| public func throwUnexpectedResponseBody(expectedContent: String, body: Any) throws -> Never { | ||
| throw RuntimeError.unexpectedResponseBody(expectedContent: expectedContent, body: body) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these could go into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to explore a better home for these, but is In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, maybe the whole file should be renamed to ErrorUtilities.swift or something, or a new ErrorFactories.swift file could hold these. Will leave up to you. |
||
Uh oh!
There was an error while loading. Please reload this page.