proshunsuke/colmsg

想定外のエラーの時にエラーメッセージが分かりにくい

Closed this issue · 0 comments

APIのマイナーバージョンが異なっていた際のエラー

[colmsg error]: HTTP status client error (400 Bad Request) for url (https://api.kh.glastonr.net/v2/groups?)

これはこちらの error_for_status を使っており、エラーになった時にレスポンスをエラーにしてしまうので、reqwestのエラーメッセージがそのまま出ている
https://docs.rs/reqwest/0.8.0/reqwest/struct.Response.html#method.error_for_status

colmsgのコードで言うとこの辺

self.handle_response(response, &request_url)

本当はその後のこの部分でエラーを込めて欲しかったが、現状あまり意味を成していない

match result {
Ok(t) => Ok(t),
Err(e) => {
let error_message = format!(
"error: {}, request url: {}, response body: {}", e.to_string(), request_url, &body
);
Err(error_message.into())
}
}