Don't unnecessarily retry downloads for expired attachments

This commit is contained in:
Niels Andriesse 2021-07-13 09:46:27 +10:00
parent 6bc9b21cde
commit 2928a8f66c
1 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import Foundation
import SessionUtilitiesKit
import SessionSnodeKit
import SignalCoreKit
public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
@ -83,6 +84,10 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
storage.setAttachmentState(to: .failed, for: pointer, associatedWith: self.tsMessageID, using: transaction)
}, completion: { })
self.handlePermanentFailure(error: error)
} else if let error = error as? OnionRequestAPI.Error, case .httpRequestFailedAtDestination(let statusCode, _) = error,
statusCode == 400 {
// This usually indicates a file that has expired on the server, so there's no need to retry.
self.handlePermanentFailure(error: error)
} else {
self.handleFailure(error: error)
}