我如何区分 SSR / API / Server Action 的错误处理方式

场景使用方式错误处理方式是否标准化结构
✅ SSR(RSC 内调用) async function throw / null / 简单异常 ❌ 不使用 { status, code, httpCode },只要报错清晰即可
✅ Route Handler 显式构造响应 BizErrorActionRespType ✅ 使用 { status, code, httpCode }
✅ Server Action 服务端可调用函数 返回标准结构 ✅ 使用 { status, code, httpCode }

设计理由:

  • SSR 的错误处理是为了开发者可控:遇错你重定向/跳转/null 渲染即可

  • API 和 Server Action 则需要结构化给前端消费:约定好的响应结构便于统一处理错误弹窗、toast、兜底处理

posted @ 2025-07-03 05:18  PEAR2020  阅读(8)  评论(0)    收藏  举报