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
This commit is contained in:
Michael Vines 2021-07-02 12:27:40 -07:00
parent d2b07dca9d
commit 40d696fcbc
1 changed files with 5 additions and 1 deletions

View File

@ -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());