-
Notifications
You must be signed in to change notification settings - Fork 26
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
[Devin] Add RetryInterceptor #52
Conversation
Package.swift
Outdated
.testTarget( | ||
name: "PapyrusCoreTests", | ||
dependencies: ["PapyrusCore"], | ||
dependencies: ["PapyrusCore", "Papyrus"], |
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.
Remove
Papyrus/URLSession+Papyrus.swift
Outdated
|
||
// MARK: Retry Interceptor | ||
|
||
/** |
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.
Make these triple slash instead of slash asterisk comments
*/ | ||
public struct RetryInterceptor: Interceptor { | ||
private let maxRetryCount: Int | ||
private let initialBackoff: UInt64 |
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.
Make this int not int64
public struct RetryInterceptor: Interceptor { | ||
private let maxRetryCount: Int | ||
private let initialBackoff: UInt64 | ||
private let exponentialBackoff: UInt64 |
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.
Int not int64
// Act | ||
let expectation = expectation(description: "The endpoint with the non-optional return type should throw an error for an invalid body.") | ||
let expectation = self.expectation(description: "The endpoint with the non-optional return type should throw an error for an invalid body.") |
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.
Remove
do { | ||
let _ = try await sut.get() | ||
} catch { | ||
expectation.fulfill() | ||
} | ||
|
||
// Assert | ||
await fulfillment(of: [expectation], timeout: 1) | ||
wait(for: [expectation], timeout: 1) |
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.
Revert
// Act | ||
let expectation = expectation(description: "The endpoint with the non-optional return type should throw an error for an invalid body.") | ||
let expectation = self.expectation(description: "The endpoint with the non-optional return type should throw an error for an invalid body.") |
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.
Remove
do { | ||
let _ = try await sut.get() | ||
} catch { | ||
expectation.fulfill() | ||
} | ||
|
||
// Assert | ||
await fulfillment(of: [expectation], timeout: 1) | ||
wait(for: [expectation], timeout: 1) |
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.
Revert
var value: String? { | ||
switch self { | ||
case .nil: | ||
nil | ||
return nil |
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.
Remove all these returns
…lean up returns in tests
repeat { | ||
do { | ||
response = try await next(req) | ||
if let statusCode = response.statusCode, (500...599).contains(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.
Probably if we implement just retry strategy - needRetry
could be an external logic instead of hardcoded one.
So we"ll be able to check anything inside response to decide if retry needed.
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.
Yep totally agree - this PR was actually made by a bot. The GitHub copilot version (other PR) does what you suggest and I think is a much better option.
Closing due to inactivity. |
Implemented a retry interceptor to handle retry logic for failed network requests with status codes 500-599, up to three retries with exponential backoff.