-
Notifications
You must be signed in to change notification settings - Fork 102
Retry pj on version error #151
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,22 @@ impl App { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(feature = "v2")] | ||
| async fn try_v1(&self, req_ctx: &mut payjoin::send::RequestContext) -> Result<Psbt> { | ||
| let (req, ctx) = req_ctx.clone().extract_v1().unwrap(); | ||
| let http = http_agent()?; | ||
| println!("Sending fallback v1 request to {} after v2 request attempt fail", &req.url); | ||
| let response = spawn_blocking(move || { | ||
| http.post(req.url.as_ref()) | ||
| .set("Content-Type", "text/plain") | ||
| .send_bytes(&req.body) | ||
| .map_err(map_ureq_err) | ||
| }) | ||
| .await??; | ||
| println!("Sent fallback v1 request"); | ||
| Ok(ctx.process_response(&mut response.into_reader())?) | ||
| } | ||
|
|
||
| #[cfg(feature = "v2")] | ||
| async fn long_poll_post(&self, req_ctx: &mut payjoin::send::RequestContext) -> Result<Psbt> { | ||
| loop { | ||
|
|
@@ -211,12 +227,18 @@ impl App { | |
| println!("Sent fallback transaction"); | ||
| match ctx.process_response(&mut response.into_reader()) { | ||
| Ok(Some(psbt)) => return Ok(psbt), | ||
| Ok(None) => std::thread::sleep(std::time::Duration::from_secs(5)), | ||
| Err(re) => { | ||
| println!("{}", re); | ||
| log::debug!("{:?}", re); | ||
| Ok(None) => { | ||
| std::thread::sleep(std::time::Duration::from_secs(5)); | ||
| continue; | ||
| } | ||
| } | ||
| Err(error) => { | ||
| if error.is_version_supported(&1) { | ||
| return self.try_v1(req_ctx).await; | ||
| }; | ||
| println!("{}", error); | ||
| log::debug!("{:?}", error); | ||
|
Comment on lines
+236
to
+239
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returning early on line 236 here will skip printing the error if one is encountered. Rather, if an error is encountered there it should run on the same log statements. This will also require Err(mut error) => {
if error.is_version_supported(&1) {
match self.try_v1(req_ctx).await {
Ok(res) => return Ok(res),
Err(e) => error = e,
}
};
println!("{}", error);
log::debug!("{:?}", error);
} |
||
| } | ||
| }; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
nit: this file both sends and receives so this fn should probably be called try_send_v1