refactor: close type holes on the transport and error axes
- OpenApiRoute.transport was typed `string`, so the compiler could not check the transport branching at all. Type it Transport and key the documented 200 off a Record, so a new transport fails the build instead of silently going undocumented. - pickEncoder fell through to ndjson for unknown transports; make the mapping exhaustive so a new transport cannot inherit the wrong wire format by accident. - HttpError carries optional headers, removing the instanceof Redirect special case that coupled the error renderer to one subclass. Custom errors needing headers (retry-after, etag) no longer require touching transformers. - Drop the module-global connSeq in mesh/link: `pending` is already per-connection, so a per-link counter suffices and connection ids stop depending on test order. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
5 files changed
+55
-36
No files matched your search
+2
-3
@@ -1,4 +1,4 @@
|
||||
import { isHttpError, Redirect, ValidationError } from './signals';
|
||||
import { isHttpError, ValidationError } from './signals';
|
||||
import type { TransformerFn } from './metadata';
|
||||
import { flattenPath } from './standard-schema';
|
||||
|
||||
@@ -47,8 +47,7 @@ export function errorToResponse(error: unknown): ErrorResponse {
|
||||
}
|
||||
|
||||
if (isHttpError(error)) {
|
||||
const headers: Record<string, string> = { 'content-type': 'application/json' };
|
||||
if (error instanceof Redirect) headers.location = error.location;
|
||||
const headers = { 'content-type': 'application/json', ...error.headers };
|
||||
const payload = error.body !== undefined ? error.body : { error: error.message };
|
||||
return { status: error.status, headers, body: JSON.stringify(payload) };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user