Skip to content

docs: extend building a middleware from scratch guide#752

Closed
samueljoli wants to merge 1 commit intotower-rs:masterfrom
samueljoli:docs-extend-building-middleware-from-scractch-guide
Closed

docs: extend building a middleware from scratch guide#752
samueljoli wants to merge 1 commit intotower-rs:masterfrom
samueljoli:docs-extend-building-middleware-from-scractch-guide

Conversation

@samueljoli
Copy link
Copy Markdown

@samueljoli samueljoli commented Nov 5, 2023

add steps:

  • create a layer
  • integration with service builder

addresses: #751

add steps: create a layer, integration with service builder
```

That's because there's an attempt to convert a Box<dyn StdError + Send + Sync + 'static> into Infallible. The Infallible type is used to signify that a function will never return an error.
> Axum’s error handling model requires handlers to always return a response. However middleware is one possible way to introduce errors into an application. If hyper receives an error the connection will be closed without sending a response. Thus axum requires those errors to be handled gracefully. - [doc](https://docs.rs/axum/latest/axum/middleware/index.html#error-handling-for-middleware)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really add specific framework mentions to these fundamental docs? Is that done elsewhere? Just asking, as I'm not sure of the value of it, given not everyone might be familiar with hyper and/or axum.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GlenDC That's a valid point. Apologies, I'm kinda new to the tokio ecosystem and didn't fully realize that tower is incredibly framework agnostic. The motivation was to provide an example of usage and what issues might come up when integrating with Axum. But you're right in that:

given not everyone might be familiar with hyper and/or axum.

Maybe this can find a home in one of Axum's examples

I can close out this PR and the accompanying Issue

@samueljoli samueljoli closed this Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants