support custom not found endpoint
- Dominant language
- Rust
- Stars
- 5.1k
- Forks
- 329
- PR merge metrics
- No merged PRs in 30d
Description
## Feature Request
Currently, Tide always returns 404 with an empty body when there is no route matched.
https://github.com/rustasync/tide/blob/9a9b10a6fa7ad3aebbebd7a2404ac4ddc4c17ab7/src/router/core.rs#L71
But, we often expect to return some message to let our user know what happened.
## Possible Implementation
To archive this goal, we have some options under current implementation:
1. set a "catch-all" route to make "not found" fallback to that handler.
2. implement a middleware to handle this situation, but how to judge things exactly right(i.e. 404 with an empty body may not cause by route missing)
3. support register an `Endpoint` which should be called when route not found.
@tzilist mentioned (#10) that we can make something like actix-web does, but actix-web `ErrorHandlers` associated handler with a status code. While seems Tide do not have trait `ResponseError`, which can provide detailed context to handle errors. For example, when returning 400, the concrete situation may be the request body can not be deserialized, or some fields in the body did not pass the verification, we often have different biz status code and error message for such scenarios, which is common needs when implementing RESTful API, with `ResponseError`, we can distinguish what happened exactly. Maybe we should consider a similar field in `Context<_>`.
---
Ref #10 #62
Contributor guide
Assessment
This issue has not been assessed yet.