From 2a10c815bebd18ad16886175f38c7ec40a09c563 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 23 Sep 2025 14:59:01 -0500 Subject: [PATCH] catcher: Add trailing newline to body text Since the API provided by this service is intended to be used on the command line e.g. with `curl`, we need our responses to have a trailing newline. This ensures that, when used interactively, the next shell prompt is correctly placed on a new line, and when used non-interactively, line-buffered output is correctly flushed (i.e. to a log file). --- src/lib.rs | 4 ++-- tests/integration/basic.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95c2a52..57b84e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ use rocket::http::Status; #[rocket::catch(default)] fn not_found(status: Status, _req: &Request) -> String { match status.reason() { - Some(s) => s.into(), - None => format!("{}", status.code), + Some(s) => format!("{s}\n"), + None => format!("{}\n", status.code), } } diff --git a/tests/integration/basic.rs b/tests/integration/basic.rs index fee2fff..9b2c4ca 100644 --- a/tests/integration/basic.rs +++ b/tests/integration/basic.rs @@ -17,5 +17,5 @@ fn test_not_found() { let client = super::client(); let response = client.get("/bogus").dispatch(); assert_eq!(response.status(), Status::NotFound); - assert_eq!(response.into_string(), Some("Not Found".into())); + assert_eq!(response.into_string(), Some("Not Found\n".into())); }