Skip to content

Timeout Middleware: Propagate Timeout as 504 Not 500 #643

Description

@SheyeJDev

Problem: middleware/timeout.ts sets a request timeout, but when the timeout fires, it calls next(new Error("Request timeout")). The errorHandler in middleware/error.ts maps unknown errors to 500. A timeout should be a 504 Gateway Timeout, not a 500 Internal Server Error.

Scope: Fix the timeout middleware to produce a 504 status code.

Implementation guidance:
In timeout.ts, throw a typed RpcTimeoutError (already defined in stellar.ts) instead of a generic Error.
In errorHandler, detect RpcTimeoutError (or a statusCode === 504 duck-type) and respond with status 504.
Add a test in timeout.test.ts.

Acceptance criteria: A simulated timeout returns HTTP 504; the error field in the response body is "timeout_error".

Validation: timeout.test.ts test passes; manual test with an artificially low timeout.

Files to modify: backend/src/middleware/timeout.ts, backend/src/middleware/error.ts

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbackendExpress API (Node/TS) workenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions