Closed danilofuchs closed 6 months ago
Describe the bug In version 1.x, to return an error, the experience was not ideal:
const notFound = { error: { json: { message: "NOT_FOUND", code: -32004, data: { code: "NOT_FOUND", httpStatus: 404, stack: "", path: "", zodError: null, }, }, meta: [], }, }; server.use( api.shipment.getAddress.query((req, res, ctx) => { return res(ctx.status(404), ctx.json(notFound)); }) )
From what I understand, 2.x improves the experience:
server.use( api.shipment.getAddress.query(() => { throw new TRPCError({ code: "NOT_FOUND", }); }) )
However, the error on the client side does not match the reality, and I couldn't find an escape hatch:
msw-trpc 2.0.0-beta.0:
{ "meta": { "response": {} }, "name": "TRPCClientError" }
trpc 10.44.1:
{ "meta": { "response": {}, "responseJSON": [ { "error": { "json": { "message": "NOT_FOUND", "code": -32004, "data": { "code": "NOT_FOUND", "httpStatus": 404, "stack": "TRPCError: NOT_FOUND ...", "path": "shipment.getAddress", "apiError": null, "zodError": null } } } } ] }, "shape": { "message": "NOT_FOUND", "code": -32004, "data": { "code": "NOT_FOUND", "httpStatus": 404, "stack": "TRPCError: NOT_FOUND ...", "path": "shipment.getAddress", "apiError": null, "zodError": null } }, "data": { "code": "NOT_FOUND", "httpStatus": 404, "stack": "TRPCError: NOT_FOUND ...", "path": "shipment.getAddress", "apiError": null, "zodError": null }, "name": "TRPCClientError" }
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Versions typescript: v5.2.2 tRPC: v10.44.1 msw: v2.0.11
@maloguertin I would like to work on this issue.
Describe the bug In version 1.x, to return an error, the experience was not ideal:
From what I understand, 2.x improves the experience:
However, the error on the client side does not match the reality, and I couldn't find an escape hatch:
msw-trpc 2.0.0-beta.0:
trpc 10.44.1:
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Versions typescript: v5.2.2 tRPC: v10.44.1 msw: v2.0.11