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
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