Skip to content

Commit

Permalink
Merge pull request #8 from growthagent/main
Browse files Browse the repository at this point in the history
Replay: Panic when cassette cannot be read
  • Loading branch information
mksh authored Aug 24, 2023
2 parents c0d3d8f + 5c12c40 commit 77644a0
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,14 @@ impl Middleware for VCRMiddleware {
let converted_response = self.vcr_to_response(vcr_response.clone());
self.record(vcr_request, vcr_response);
Ok(converted_response)
}
},
VCRMode::Replay => {
let vcr_response = self.find_response_in_vcr(vcr_request).unwrap_or(
// Empty 404 response
vcr_cassette::Response {
body: vcr_cassette::Body::from_str("").unwrap(),
http_version: Some(vcr_cassette::Version::Http1_1),
status: vcr_cassette::Status {
code: 404,
message: "Not found in VCR".to_string(),
},
headers: HashMap::new(),
},
let vcr_response = self.find_response_in_vcr(vcr_request).unwrap_or_else(||
panic!("Can not read cassette contents from {:?}", self.path)
);
let response = self.vcr_to_response(vcr_response);
Ok(response)
}
},
}
}
}
Expand Down

0 comments on commit 77644a0

Please sign in to comment.