-
- Notifications
You must be signed in to change notification settings - Fork 455
Parameterize HttpApi base errorSchema #5654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
| I'm not sure this will work as intended, in |
| @gcanti yes -- it converts ParseError to HttpApiDecodeError. But at a later point, the (now overridable) schema is used to encode that HttpApiDecodeError for the wire. So no matter the origin of the HttpApiDecodeError, the schema is still going to work, as far as I understand it. At least in my limited testing, it worked for both the OpenApi output and the encoding of Decode Errors. |
| I see, I'll let @tim-smart chime in then |
| I initially worked on a version where the user-supplied type of the encoded HttpApiDecodeError was threaded as a generic type through the HttpApp, but eventually found that this wasn't necessary. And the user supplied schema doesn't even need to be lossless, it's fine to "encode" every HttpApiDecodeError to the value |
| @tim-smart could you please take a look at this? Most of the diff is just a new test fixture, the actual change is just ~10 loc. |
packages/platform/src/HttpApi.ts Outdated
| export const make = <const Id extends string>(identifier: Id): HttpApi<Id, never, HttpApiDecodeError> => | ||
| export const make = <const Id extends string>( | ||
| identifier: Id, | ||
| errorSchema: Schema.Schema<HttpApiDecodeError, any> = HttpApiDecodeError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be an options object, and instead of any you can use an discarded generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I try to use a discarded generic, TypeScript issues:
Type 'typeof HttpApiDecodeError' is not assignable to type 'Schema<HttpApiDecodeError, E, never>'. Types of property 'Encoded' are incompatible. Type '{ readonly _tag: "HttpApiDecodeError"; readonly message: string; readonly issues: readonly { readonly _tag: "Type" | "Pointer" | "Unexpected" | "Missing" | "Composite" | "Refinement" | "Transformation" | "Forbidden"; readonly message: string; readonly path: readonly (string | ... 1 more ... | { ...; })[]; }[]; }' is not assignable to type 'E'. 'E' could be instantiated with an arbitrary type which could be unrelated to '{ readonly _tag: "HttpApiDecodeError"; readonly message: string; readonly issues: readonly { readonly _tag: "Type" | "Pointer" | "Unexpected" | "Missing" | "Composite" | "Refinement" | "Transformation" | "Forbidden"; readonly message: string; readonly path: readonly (string | ... 1 more ... | { ...; })[]; }[]; }'. (ts 2322) It's because allowing a user to supply E may invalidate the default parameter we're trying to assign.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use an options object
1dda206 to 69e0599 Compare This allows users to customize how HttpApiDecodeErrors are represented on the wire, enabling the use of HttpApi for wire protocols that don't follow the Tagged Error approach to encoding errors.
69e0599 to fc20fc2 Compare
Type
Description
This allows users to customise how HttpApiDecodeErrors are represented on the wire, enabling the use of HttpApi for wire protocols that don't follow the Tagged Error approach to encoding errors.
Related