github unnoq/orpc v0.28.0

latest releases: v1.8.7, v1.8.6, v1.8.5...
8 months ago

🤯 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.

   🚨 Breaking Changes

  • End-to-end typesafe error handling, remove @orpc/react and @orpc/next  -  by @unnoq in #77 (9b3a0)
    View changes on GitHub

Don't miss a new orpc release

NewReleases is sending notifications on new releases.