oRPC
background

Error Handling

How to intercept, handle or log errors inside oRPC

import { ,  } from '@orpc/server'
 
const  = 
    .(async (, , ) => {
        try {
            const  = await .({})
            const  = . // do something on success
            return 
        } catch () {
            // do something on error
            throw 
        } finally {
            // do something on finish
        }
    })
    .((, , ) => {
        throw new ({
            : 'NOT_FOUND',
            : 'Not found',
            : 404, // Optional: custom default behavior
            : { : 'include in the body and send to the client' } // pass data to the client
        })
    })

On this page

No Headings