improvement(api): use HttpError base class for typed-error status mapping#4746
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview
Reviewed by Cursor Bugbot for commit c77b8a3. Configure here. |
Greptile SummaryThis PR replaces duck-typing on a
Confidence Score: 5/5Safe to merge; the change is a targeted, backward-compatible hardening of the route error handler with no altered behavior for existing callers. Both migrated error classes retain the same statusCode values and message content, so HTTP responses are unchanged. PresignedUrlError is caught by a local try/catch and never reaches withRouteHandler. RateLimitError carries a statusCode field but is not thrown from any route handler in the current codebase, so no response code regresses to 500. No files require special attention; the only note is lib/core/rate-limiter/types.ts, which defines RateLimitError outside the new HttpError hierarchy, but this class is not thrown from production route handlers today. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant withRouteHandler
participant readTypedErrorStatus
participant HttpError
Client->>withRouteHandler: HTTP request
withRouteHandler->>withRouteHandler: await handler(request, context)
note over withRouteHandler: throws error
withRouteHandler->>readTypedErrorStatus: readTypedErrorStatus(error)
readTypedErrorStatus->>HttpError: error instanceof HttpError?
alt is HttpError subclass (e.g. WorkspaceAccessDeniedError 403, InvalidFieldError 400)
HttpError-->>readTypedErrorStatus: true
readTypedErrorStatus->>readTypedErrorStatus: "check 400 <= statusCode < 600"
readTypedErrorStatus-->>withRouteHandler: typed status (4xx/5xx)
withRouteHandler-->>Client: "JSON { error: message } with typed status"
else plain Error or third-party error
HttpError-->>readTypedErrorStatus: false
readTypedErrorStatus-->>withRouteHandler: undefined
withRouteHandler-->>Client: "JSON { error: 'Internal server error' } 500"
end
Reviews (2): Last reviewed commit: "chore(api): drop unreachable runtime che..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c77b8a3. Configure here.
Summary
HttpErrorabstract base class inlib/core/utils/http-error.tswithRouteHandlernow checksinstanceof HttpErrorinstead of duck-typing onstatusCode— matches NestJSHttpException/ SpringResponseStatusExceptionpatternstatusCode-shaped field could be promoted to a typed HTTP response and leak its rawmessageWorkspaceAccessDeniedErrorandInvalidFieldErrorextendHttpErrorType of Change
Testing
bun run check:api-validationpassestsc --noEmitfor apps/sim cleanChecklist