Allow customize how HTTP errors are rendered when `websocket.Accept` fails to upgrade
- 主要语言
- Go
- 星标
- 5.5k
- 派生
- 372
- PR 合并指标
- 30 天内没有已合并 PR
描述
IDEA: Might be as simple as a new `HttpErrorRenderer` (or `OnError`, etc.) option added to `websocket.AcceptOptions`. When unspecified, default to a fn that implements current rendering behavior. It would take at minimum a `ctx`, the `err` and the http `status` code.
Nice addition: the full set of `errors.New("..")` would be exposed to user so that one can use `errors.Is` to get more granularity than provided http statuses.
We need this feature in order to produce (a standardized JSON error response format) when an error occurs in order to match the rest of our API which produces this error response format for all of its endpoints. Current hard-coded behavior prevents us to comply with our policy when WS upgrade fails in this library. Our user thus can't systematically assume this nice JSON format and must workaround this limitation...
贡献指南
这个仓库没有索引到贡献指南
调研方向
从 websocket.Accept 和 websocket.AcceptOptions 入手,检查升级失败时当前使用的 HTTP 错误呈现方式。定义可配置的错误呈现行为,同时保留现有默认行为,然后验证调用方能够生成其所需的 JSON 错误响应,并按描述区分错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go
- 领域
- backend-api-design, networking
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100