Skip to content

Commit c385f96

Browse files
committed
Enumerate errors for peek_with_timeout
1 parent d940ed2 commit c385f96

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

payjoin-directory/src/db.rs

Lines changed: 5 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,15 @@ 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(&self, subdirectory_id: &str) -> Result<RedisResult<Vec<u8>>, Elapsed> {
2728
self.peek_with_timeout(subdirectory_id, DEFAULT_COLUMN).await
2829
}
2930

3031
pub async fn push_v1(&self, subdirectory_id: &str, data: Vec<u8>) -> RedisResult<()> {
3132
self.push(subdirectory_id, PJ_V1_COLUMN, data).await
3233
}
3334

34-
pub async fn peek_v1(&self, subdirectory_id: &str) -> Option<RedisResult<Vec<u8>>> {
35+
pub async fn peek_v1(&self, subdirectory_id: &str) -> Result<RedisResult<Vec<u8>>, Elapsed> {
3536
self.peek_with_timeout(subdirectory_id, PJ_V1_COLUMN).await
3637
}
3738

@@ -52,8 +53,8 @@ impl DbPool {
5253
&self,
5354
subdirectory_id: &str,
5455
channel_type: &str,
55-
) -> Option<RedisResult<Vec<u8>>> {
56-
tokio::time::timeout(self.timeout, self.peek(subdirectory_id, channel_type)).await.ok()
56+
) -> Result<RedisResult<Vec<u8>>, Elapsed> {
57+
tokio::time::timeout(self.timeout, self.peek(subdirectory_id, channel_type)).await
5758
}
5859

5960
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)