Skip to content

fix: return proper HTTP status codes and remove input coercion#129

Merged
coji merged 1 commit intomainfrom
fix/http-error-handling
Mar 16, 2026
Merged

fix: return proper HTTP status codes and remove input coercion#129
coji merged 1 commit intomainfrom
fix/http-error-handling

Conversation

@coji
Copy link
Owner

@coji coji commented Mar 16, 2026

Summary

Two issues fixed in one PR:

#125: HTTP API returns 500 for client errors

Added typed error classes (DurablyError, NotFoundError, ValidationError, ConflictError) that carry HTTP status codes. withErrorHandling now maps them to proper responses:

Error Status Example
NotFoundError 404 Run not found, unknown job
ValidationError 400 Zod input validation failure
ConflictError 409 Retrigger pending run, cancel completed run, delete leased run
Other Error 500 Unexpected internal errors

#127: POST /trigger coerces null/missing input to {}

Removed body.input ?? {}. Input is now passed as-is to job.trigger(), letting Zod validation return a proper 400 for invalid input.

Closes #125
Closes #127

Files changed

  • errors.ts — New error classes
  • durably.ts — Use typed errors in retrigger/cancel/deleteRun
  • job.ts — Use ValidationError for Zod failures
  • server.ts — Map DurablyError to HTTP status in withErrorHandling
  • http.ts — Add 409 to status code union
  • index.ts — Export new error classes
  • server.shared.ts — Update tests to expect 409 instead of 500

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • バグ修正

    • 再トリガーと完了済み実行のキャンセル時に、正確なHTTP 409ステータスコードを返すように修正しました(以前は500)。
  • 新機能

    • NotFoundError、ConflictError、ValidationErrorの新しいエラータイプをエクスポートし、より詳細なエラーハンドリングが可能になりました。

@vercel
Copy link

vercel bot commented Mar 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
durably-demo Ready Ready Preview Mar 16, 2026 11:45am
durably-demo-vercel-turso Ready Ready Preview Mar 16, 2026 11:45am

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Warning

Rate limit exceeded

@coji has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e23b78b1-4502-4519-b088-177de51bc32f

📥 Commits

Reviewing files that changed from the base of the PR and between fd20d7d and b522887.

📒 Files selected for processing (7)
  • packages/durably/src/durably.ts
  • packages/durably/src/errors.ts
  • packages/durably/src/http.ts
  • packages/durably/src/index.ts
  • packages/durably/src/job.ts
  • packages/durably/src/server.ts
  • packages/durably/tests/shared/server.shared.ts
📝 Walkthrough

Walkthrough

汎用的なエラーを型付きエラークラス(NotFoundError、ValidationError、ConflictError)に置き換え、それぞれに対応するHTTPステータスコード(404、400、409)をマップする新しいエラー階層を導入しました。

Changes

Cohort / File(s) Summary
新しいエラー階層の導入
packages/durably/src/errors.ts
DurablyErrorベースクラスと、NotFoundError(404)、ValidationError(400)、ConflictError(409)の3つの派生クラスを追加。statusCodeプロパティを含むエラーオブジェクト構造を定義。
エラー処理の実装
packages/durably/src/durably.ts
getRunOrThrow、retrigger、cancel、deleteRun等の操作で、汎用Errorの代わりにNotFoundErrorとConflictErrorを使用。
ジョブ入力検証
packages/durably/src/job.ts
入力値の検証失敗時に、汎用Errorではなく新しいValidationErrorを投出。
エラーハンドリングとルーティング
packages/durably/src/server.ts
DurablyErrorの検出時に、statusCodeプロパティを抽出してHTTP応答にマップ。またbody.input ?? {}の処理を単純化。
公開API拡張
packages/durably/src/index.ts
DurablyError、NotFoundError、ValidationError、ConflictErrorをパッケージの公開エクスポートに追加。
HTTPシグネチャ更新
packages/durably/src/http.ts
errorResponse関数のstatus パラメータに409を追加(400|404|409|500)。
テスト期待値の更新
packages/durably/tests/shared/server.shared.ts
retriggerおよびcancel操作のHTTPステータス期待値を500から409に修正。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 エラーたちが整列して
404、409、400に分かれて
ステータスコードの正しい家へ
帰って行くよ、誤りなく
サーバーの心、スッキリさ ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは「fix: return proper HTTP status codes and remove input coercion」で、PRの2つの主要な目的(HTTPステータスコード修正と入力強制の削除)を正確に要約している。
Linked Issues check ✅ Passed #125と#127のすべての目的が実装されている:型付きエラークラスの導入、エラーのHTTPステータスマッピング、body.input??{}の削除、Zod検証への委譲。
Out of Scope Changes check ✅ Passed すべての変更はHTTPステータスコード修正と入力強制削除という明示的な目的に対応している。無関係な機能追加や変更は見当たらない。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/http-error-handling
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

#125: HTTP API now returns correct status codes:
- 400 for validation errors (bad input, malformed JSON)
- 404 for not found (run, job)
- 409 for conflict (retrigger pending/leased, cancel completed, delete active)
- 500 only for unexpected internal errors

Added typed error classes: DurablyError, NotFoundError, ValidationError,
ConflictError — all exported for user-land error handling.

#127: Remove all input coercion in POST /trigger. body.input is passed
directly to job.trigger() — Zod handles validation and returns 400 for
invalid/missing input. No more silent null→{} or undefined→{} conversion.

Closes #125
Closes #127

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coji coji force-pushed the fix/http-error-handling branch from e911378 to b522887 Compare March 16, 2026 11:44
@coji coji merged commit 6645766 into main Mar 16, 2026
5 checks passed
@coji coji deleted the fix/http-error-handling branch March 16, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: POST /trigger silently coerces null and missing input to {} fix: HTTP API returns 500 for client errors

1 participant