feat(signals): recognise HTTP errors by brand, not by instanceof
A plugin published as its own package cannot import HttpError without depending on core's version, and under CalVer no dependency range survives next month's beta. A Symbol.for brand crosses copies, so a plugin throws a 429 core renders, while importing nothing but types. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+107
-5
No files matched your search
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { isHttpError, ValidationError } from './signals';
|
||||
import { isHttpError, isValidationError } from './signals';
|
||||
import type { TransformerFn } from './metadata';
|
||||
import { flattenPath } from './standard-schema';
|
||||
import type { Logger } from './logger';
|
||||
@@ -35,7 +35,7 @@ export const JsonTransformer: TransformerFn = (value) => ({
|
||||
* An `HttpError` carrying a `body` renders that payload instead of the default `{ error: message }`.
|
||||
*/
|
||||
export function errorToResponse(error: unknown): ErrorResponse {
|
||||
if (error instanceof ValidationError) {
|
||||
if (isValidationError(error)) {
|
||||
return {
|
||||
status: 422,
|
||||
headers: { 'content-type': 'application/json' },
|
||||
|
||||
Reference in new issue
Block a user