知识卡片
异常类型区分失败来源
服务内部可用不同异常类型区分资源不存在、外部 API 集成失败和业务动作无效。调用方由此能针对错误性质选择响应与补救方式,而不必从模糊错误字符串推断。异常分类应与实际触发条件对应,不能用同一类错误掩盖超时、拒绝和状态冲突的差别。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 7 章《Service implementation patterns for microservices》(源文件:_epub-src/OEBPS/Text/07.htm)
- 结论依据:原文分别定义 `OrderNotFoundError`、`APIIntegrationError` 与 `InvalidActionError`,并在订单服务和外部调用失败时按场景抛出。
- 原始内容:We’ll use OrderNotFoundError in the OrdersService class when a user tries to fetch the details of an order that doesn’t exist. ... ① Exception to signal that an order doesn’t exist ② Exception to signal that an API integration error has taken place ③ Exception to signal that the action being performed is invalid