32 lines
908 B
Plaintext
32 lines
908 B
Plaintext
//#region src/ssr/serializer/ShallowErrorPlugin.ts
|
|
/**
|
|
* this plugin serializes only the `message` part of an Error
|
|
* this helps with serializing e.g. a ZodError which has functions attached that cannot be serialized
|
|
*/
|
|
const ShallowErrorPlugin = /* @__PURE__ */ (0, require("seroval").createPlugin)({
|
|
tag: "$TSR/Error",
|
|
test(value) {
|
|
return value instanceof Error;
|
|
},
|
|
parse: {
|
|
sync(value, ctx) {
|
|
return { message: ctx.parse(value.message) };
|
|
},
|
|
async async(value, ctx) {
|
|
return { message: await ctx.parse(value.message) };
|
|
},
|
|
stream(value, ctx) {
|
|
return { message: ctx.parse(value.message) };
|
|
}
|
|
},
|
|
serialize(node, ctx) {
|
|
return "new Error(" + ctx.serialize(node.message) + ")";
|
|
},
|
|
deserialize(node, ctx) {
|
|
return new Error(ctx.deserialize(node.message));
|
|
}
|
|
});
|
|
//#endregion
|
|
exports.ShallowErrorPlugin = ShallowErrorPlugin;
|
|
|
|
//# sourceMappingURL=ShallowErrorPlugin.cjs.map |