知识卡片

普通读书笔记卡 · 3500

异常类型区分失败来源

理解等级:中级

服务内部可用不同异常类型区分资源不存在、外部 API 集成失败和业务动作无效。调用方由此能针对错误性质选择响应与补救方式,而不必从模糊错误字符串推断。异常分类应与实际触发条件对应,不能用同一类错误掩盖超时、拒绝和状态冲突的差别。

这张卡片看不懂?

已有反馈 · 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