Skip to content

Commit

Permalink
Fix error response builder, missing Content-Type header (#808)
Browse files Browse the repository at this point in the history
* fix error response builder, missing content-type header

* fix StaticFileError `as_response` implementation
  • Loading branch information
Mr-Leshiy committed May 11, 2024
1 parent f6bec88 commit 40b2696
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions poem/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub trait ResponseError {
where
Self: StdError + Send + Sync + 'static,
{
Response::builder()
.status(self.status())
.body(self.to_string())
let mut resp = self.to_string().into_response();
resp.set_status(self.status());
resp
}
}

Expand Down Expand Up @@ -980,9 +980,8 @@ impl ResponseError for StaticFileError {
}

fn as_response(&self) -> Response {
let mut resp = Response::builder()
.status(self.status())
.body(self.to_string());
let mut resp = self.to_string().into_response();
resp.set_status(self.status());
if let StaticFileError::RangeNotSatisfiable { size } = self {
resp.headers_mut()
.typed_insert(ContentRange::unsatisfied_bytes(*size));
Expand Down

0 comments on commit 40b2696

Please sign in to comment.