mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Merge pull request #150 from teloxide/invalid_json_raw
Add `RequestError::InvalidJson::raw` field
This commit is contained in:
commit
54f4281754
3 changed files with 17 additions and 7 deletions
|
@ -37,10 +37,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Use `url::Url` for urls, use `chrono::DateTime<Utc>` for dates in types ([#115][pr115])
|
||||
- Mark `ApiError` as `non_exhaustive` ([#125][pr125])
|
||||
- `InputFile` and related structures now do **not** implement `PartialEq`, `Eq` and `Hash` ([#133][pr133])
|
||||
- `RequestError::InvalidJson` now has a `raw` field with raw json for easier debugability ([#150][pr150])
|
||||
|
||||
[pr115]: https://github.com/teloxide/teloxide-core/pull/115
|
||||
[pr125]: https://github.com/teloxide/teloxide-core/pull/125
|
||||
[pr134]: https://github.com/teloxide/teloxide-core/pull/134
|
||||
[pr150]: https://github.com/teloxide/teloxide-core/pull/150
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -43,8 +43,13 @@ pub enum RequestError {
|
|||
/// description of the error.
|
||||
///
|
||||
/// [open an issue]: https://github.com/teloxide/teloxide/issues/new
|
||||
#[error("An error while parsing JSON: {0}")]
|
||||
InvalidJson(#[source] serde_json::Error),
|
||||
#[error("An error while parsing JSON: {source} (raw: {raw:?})")]
|
||||
InvalidJson {
|
||||
#[source]
|
||||
source: serde_json::Error,
|
||||
/// The raw string JSON that couldn't been parsed
|
||||
raw: Box<str>,
|
||||
},
|
||||
|
||||
/// Occurs when trying to send a file to Telegram.
|
||||
#[error("An I/O error: {0}")]
|
||||
|
|
|
@ -85,9 +85,12 @@ where
|
|||
tokio::time::sleep(DELAY_ON_SERVER_ERROR).await;
|
||||
}
|
||||
|
||||
serde_json::from_str::<TelegramResponse<T>>(
|
||||
&response.text().await.map_err(RequestError::Network)?,
|
||||
)
|
||||
.map_err(RequestError::InvalidJson)?
|
||||
.into()
|
||||
let text = response.text().await.map_err(RequestError::Network)?;
|
||||
|
||||
serde_json::from_str::<TelegramResponse<T>>(&text)
|
||||
.map_err(|source| RequestError::InvalidJson {
|
||||
source,
|
||||
raw: text.into(),
|
||||
})?
|
||||
.into()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue