From 40d696fcbcf5ddb6f01ad4da3215c9d126a85f94 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 2 Jul 2021 12:27:40 -0700 Subject: [PATCH] Report 404 instead of 502 when a snapshot file is not found This provides the client with more useful information about why their request failed --- rpc/src/rpc_service.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rpc/src/rpc_service.rs b/rpc/src/rpc_service.rs index 8cec93a302..8dd85128c1 100644 --- a/rpc/src/rpc_service.rs +++ b/rpc/src/rpc_service.rs @@ -164,7 +164,11 @@ impl RpcRequestMiddleware { should_validate_hosts: true, response: Box::pin(async { match Self::open_no_follow(filename).await { - Err(_) => Ok(Self::internal_server_error()), + Err(err) => Ok(if err.kind() == std::io::ErrorKind::NotFound { + Self::not_found() + } else { + Self::internal_server_error() + }), Ok(file) => { let stream = FramedRead::new(file, BytesCodec::new()).map_ok(|b| b.freeze());