Skip to content

Commit 05014cd

Browse files
committed
sentry - ResponseError fix issue with BadRequest
1 parent 3c4d2b7 commit 05014cd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

primitives/examples/channel_pay_request.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use primitives::sentry::ChannelPayRequest;
22
use serde_json::json;
3-
use std::str::FromStr;
43

54
fn main() {
65
let channel_pay_json = json!({

sentry/src/response.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ impl IntoResponse for ResponseError {
2121
ResponseError::NotFound => {
2222
(StatusCode::NOT_FOUND, "Not found".to_string()).into_response()
2323
}
24-
ResponseError::BadRequest(err) => (StatusCode::BAD_REQUEST, err).into_response(),
24+
ResponseError::BadRequest(err) => {
25+
let error_response = [("message", err)].into_iter().collect::<HashMap<_, _>>();
26+
27+
(StatusCode::BAD_REQUEST, Json(error_response)).into_response()
28+
}
2529
ResponseError::Unauthorized => {
2630
(StatusCode::UNAUTHORIZED, "invalid authorization").into_response()
2731
}
@@ -46,9 +50,7 @@ where
4650
T: std::error::Error + 'static,
4751
{
4852
fn from(error: T) -> Self {
49-
// @TODO use a error proper logger?
50-
println!("{:#?}", error);
51-
ResponseError::BadRequest("Bad Request: try again later".into())
53+
ResponseError::BadRequest(error.to_string())
5254
}
5355
}
5456
impl From<ResponseError> for Response<Body> {

0 commit comments

Comments
 (0)