Error Handling
How to intercept, handle or log errors inside oRPC
import { ORPCError, os } from '@orpc/server'
const ping = os
.use(async (input, context, meta) => {
try {
const result = await meta.next({})
const _output = result.output // do something on success
return result
} catch (e) {
// do something on error
throw e
} finally {
// do something on finish
}
})
.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
})
})