From 711e4dc0fd744eb92b3b7ffe9390eab6c1907ad0 Mon Sep 17 00:00:00 2001 From: Alex Deem Date: Mon, 8 Jan 2024 13:30:40 +1100 Subject: [PATCH] Don't crash if an unexpected request is intercepted Complete with an error instead. --- Sources/DVR/SessionDataTask.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/DVR/SessionDataTask.swift b/Sources/DVR/SessionDataTask.swift index fe44b23..7c6af83 100644 --- a/Sources/DVR/SessionDataTask.swift +++ b/Sources/DVR/SessionDataTask.swift @@ -1,5 +1,9 @@ import Foundation +enum DVRError: Error { + case interactionNotFound +} + final class SessionDataTask: URLSessionDataTask { // MARK: - Types @@ -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.