Error Handling
How to intercept, handle or log errors inside oRPC
import { ORPCError, os } from '@orpc/server'
const ping = os
.use((input, context, meta) => {
meta.onError(async (error) => {
if(!(error instanceof ORPCError)) return;
console.log(error.code, error.message, error.data)
// do something here
})
meta.onSuccess((output) => {})
meta.onFinish((output, error) => {})
})
.handler((input, context, meta) => {
throw new ORPCError({
code: 'NOT_FOUND',
message: 'Not found',
status: 404, // Optional: custom default behavior
data: { something: 'include in the body and send to the client' } // pass data to the client
})
})