🤯 End-to-End Typesafe Error Handling 🤯
const createPost = os
.errors({
CONFLICT: {
data: z.object({
why: z.string(),
}),
},
})
.handler(({ errors }) => {
throw errors.CONFLICT({ data: { why: 'some reason' } })
})
const [data, error] = await safe(createPost({ title: 'title' }))
if (error && isDefinedError(error)) {
const data = error.data // { why: 'some reason' } full typed data
}
const mutation = useMutation(orpc.createPost.mutationOptions({
onError(error) {
if (isDefinedError(error)) {
const data = error.data // { why: 'some reason' } full typed data
}
},
}))
- Removed
@orpc/react
since it was too complicated to maintain, while@orpc/react-query
is simpler and easier to maintain while achieve the same functionality. - Temporarily removed
@orpc/next
due to unexpected behavior from Next.js. You can follow progress here. I will bring this package back in a future oRPC version.