Skip to content

Commit 411577d

Browse files
committed
Implement From<&EventError> for HttpResponse
Previously, it was only implemented for `EventError`, which required giving up ownership for no good reason.
1 parent d34f7bb commit 411577d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

openapi-lambda/src/error.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,22 @@ impl EventError {
136136
}
137137
}
138138

139+
// For convenience.
139140
impl From<EventError> for HttpResponse {
141+
fn from(err: EventError) -> HttpResponse {
142+
(&err).into()
143+
}
144+
}
145+
146+
impl From<&EventError> for HttpResponse {
140147
/// Build a client-facing [`HttpResponse`] appropriate for the error that occurred.
141148
///
142149
/// This function will set the appropriate HTTP status code (400 or 500) depending on whether the
143150
/// error is internal (500) or caused by the client (400). For client errors, the
144151
/// response body contains a human-readable description of the error and the `Content-Type`
145152
/// response header is set to `text/plain`. For internal errors, no response body is returned to
146153
/// the client.
147-
fn from(err: EventError) -> HttpResponse {
154+
fn from(err: &EventError) -> HttpResponse {
148155
let (status_code, body) = match err {
149156
// 400
150157
EventError::InvalidBodyJson(err, _) => (

0 commit comments

Comments
 (0)