Skip to content

Commit

Permalink
Change sse::Event::json_data to use axum_core::Error as its error…
Browse files Browse the repository at this point in the history
… type

I don't think it was intentional to use `serde_json::Error` and we don't
generally use that elsewhere we do JSON things.

Discovered this with <https://github.com/davidpdrsn/cargo-public-api-crates>
  • Loading branch information
davidpdrsn committed Feb 16, 2023
1 parent 3897efd commit d0c88f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- None.
- **breaking:** Change `sse::Event::json_data` to use `axum_core::Error` as its error type ([#1762])

[#1762]: https://github.com/tokio-rs/axum/pull/1762

# 0.6.6 (12. February, 2023)

Expand Down
1 change: 0 additions & 1 deletion axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ allowed = [
"http_body",
"hyper",
"serde",
"serde_json",
"tower_layer",
"tower_service",
]
Expand Down
4 changes: 2 additions & 2 deletions axum/src/response/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Event {
///
/// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data
#[cfg(feature = "json")]
pub fn json_data<T>(mut self, data: T) -> serde_json::Result<Event>
pub fn json_data<T>(mut self, data: T) -> Result<Event, axum_core::Error>
where
T: serde::Serialize,
{
Expand All @@ -219,7 +219,7 @@ impl Event {
}

self.buffer.extend_from_slice(b"data:");
serde_json::to_writer((&mut self.buffer).writer(), &data)?;
serde_json::to_writer((&mut self.buffer).writer(), &data).map_err(axum_core::Error::new)?;
self.buffer.put_u8(b'\n');

self.flags.insert(EventFlags::HAS_DATA);
Expand Down

0 comments on commit d0c88f6

Please sign in to comment.