fix(dispatch): 後台強制取消的狀態衝突回 409,不要一律 500 - #69
Merged
Conversation
`AdminHandler.CancelRide` 只把 ErrNotFound 判 404,其餘全丟 500。 於是兩種後台每天會遇到的正常情況都變成「伺服器錯誤」: 已上車無法取消(確認對話框自己就寫著這句),以及上一次其實已經取消成功 (回應遺失後操作者又按了一次)。 乘客端的 readStatusForErr 從 T1 起就把這一族判 409 並寫明理由, admin 這支是漏網的。 不是只換個數字:500 讓監控把例行操作當成故障,也讓前端無從分辨 「伺服器壞了」與「這件事已經生效了,重讀一次就對了」——後者正是 admin 該自動重新整理的訊號(同批的 admin PR 就是靠 409 做這件事)。 驗收:抽出 adminCancelStatus 純函式+5 案表格測試(含包過一層仍成立); 反向確認改回 500 只有那兩案 FAIL;gofmt/go vet/go build 乾淨。 真後端實跑:已取消再取消 409、已上車 409、不存在仍是 404。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
AdminHandler.CancelRide只把ErrNotFound判 404,其餘一律 500。兩種後台每天都會遇到的正常情況因此變成「伺服器錯誤」:
ErrRideStartedErrRideStateChangedErrNotFound乘客端的
readStatusForErr從 T1 起就把這一族判 409 並寫明理由,admin 這支是漏網的。為什麼不是「只換個數字」
500 有兩個實際後果:監控把例行操作當成伺服器故障;
前端無從分辨「伺服器壞了」與「這件事已經生效了,重讀一次就對了」。
後者正是 admin 該自動重新整理的訊號——同批的
line-fleet-admin PR 就是靠 409 做這件事。
這個缺口是在 admin 那側盤點「寫入其實成功卻報失敗」的畫面時實跑撞到的:
代理吃掉取消的回應(後端其實已取消)→ 畫面說「請求逾時,請稍後再試」→
操作者照著再按一次 → 拿到
500 訂單狀態已變更,無法取消。驗收
adminCancelStatus(err)純函式 + 5 案表格測試(含「包過一層%w仍要成立」)。gofmt/go vet/go build乾淨。已上車的 feat(O6+P5): 寵物車清潔費(計費/落帳/報表分項)+乘客可讀費率端點 #31 → 409
行程已開始,無法取消;不存在的 #999999 → 404(沒有連帶改壞)。🤖 Generated with Claude Code