Skip to content

Commit

Permalink
Don't crash if an unexpected request is intercepted
Browse files Browse the repository at this point in the history
Complete with an error instead.
  • Loading branch information
alexdeem committed Jan 8, 2024
1 parent 0438c04 commit 711e4dc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/DVR/SessionDataTask.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Foundation

enum DVRError: Error {
case interactionNotFound
}

final class SessionDataTask: URLSessionDataTask {

// MARK: - Types
Expand Down Expand Up @@ -70,7 +74,10 @@ final class SessionDataTask: URLSessionDataTask {
}

if cassette != nil {
fatalError("[DVR] Invalid request. The request was not found in the cassette.")
if let completion = self.completion {
completion(nil, nil, DVRError.interactionNotFound as NSError)
}
return
}

// Cassette is missing. Record.
Expand Down

0 comments on commit 711e4dc

Please sign in to comment.