Skip to content

Commit 7f27c9d

Browse files
committed
Enumerate errors for peek_with_timeout
1 parent d940ed2 commit 7f27c9d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

payjoin-directory/src/db.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::time::Duration;
22

33
use futures::StreamExt;
44
use redis::{AsyncCommands, Client, ErrorKind, RedisError, RedisResult};
5+
use tokio::time::error::Elapsed;
56
use tracing::debug;
67

78
const DEFAULT_COLUMN: &str = "";
@@ -23,15 +24,18 @@ impl DbPool {
2324
self.push(subdirectory_id, DEFAULT_COLUMN, data).await
2425
}
2526

26-
pub async fn peek_default(&self, subdirectory_id: &str) -> Option<RedisResult<Vec<u8>>> {
27+
pub async fn peek_default(
28+
&self,
29+
subdirectory_id: &str,
30+
) -> Result<RedisResult<Vec<u8>>, Elapsed> {
2731
self.peek_with_timeout(subdirectory_id, DEFAULT_COLUMN).await
2832
}
2933

3034
pub async fn push_v1(&self, subdirectory_id: &str, data: Vec<u8>) -> RedisResult<()> {
3135
self.push(subdirectory_id, PJ_V1_COLUMN, data).await
3236
}
3337

34-
pub async fn peek_v1(&self, subdirectory_id: &str) -> Option<RedisResult<Vec<u8>>> {
38+
pub async fn peek_v1(&self, subdirectory_id: &str) -> Result<RedisResult<Vec<u8>>, Elapsed> {
3539
self.peek_with_timeout(subdirectory_id, PJ_V1_COLUMN).await
3640
}
3741

@@ -52,8 +56,8 @@ impl DbPool {
5256
&self,
5357
subdirectory_id: &str,
5458
channel_type: &str,
55-
) -> Option<RedisResult<Vec<u8>>> {
56-
tokio::time::timeout(self.timeout, self.peek(subdirectory_id, channel_type)).await.ok()
59+
) -> Result<RedisResult<Vec<u8>>, Elapsed> {
60+
tokio::time::timeout(self.timeout, self.peek(subdirectory_id, channel_type)).await
5761
}
5862

5963
async fn peek(&self, subdirectory_id: &str, channel_type: &str) -> RedisResult<Vec<u8>> {

payjoin-directory/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ async fn post_fallback_v1(
341341
.await
342342
.map_err(|e| HandlerError::BadRequest(e.into()))?;
343343
match pool.peek_v1(id).await {
344-
Some(result) => match result {
344+
Ok(result) => match result {
345345
Ok(buffered_req) => Ok(Response::new(full(buffered_req))),
346346
Err(e) => Err(HandlerError::BadRequest(e.into())),
347347
},
348-
None => Ok(none_response),
348+
_ => Ok(none_response),
349349
}
350350
}
351351

@@ -409,11 +409,11 @@ async fn get_subdir(
409409
trace!("get_subdir");
410410
let id = check_id_length(id)?;
411411
match pool.peek_default(id).await {
412-
Some(result) => match result {
412+
Ok(result) => match result {
413413
Ok(buffered_req) => Ok(Response::new(full(buffered_req))),
414414
Err(e) => Err(HandlerError::BadRequest(e.into())),
415415
},
416-
None => Ok(Response::builder().status(StatusCode::ACCEPTED).body(empty())?),
416+
_ => Ok(Response::builder().status(StatusCode::ACCEPTED).body(empty())?),
417417
}
418418
}
419419

0 commit comments

Comments
 (0)