-
|
Hello, I am trying out ORPC and have a route which fails with an unhandled error like so: export const router = {
someroute: os.someroute.handler(async () => {
throw new Error("Oh no");
}),
};This results in a 500 error |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @evrys! I'm Dosu and I’m helping the orpc team. You can log underlying errors and stack traces in ORPC by adding custom error handling middleware or using the Here's a pattern you can use: import { onError, ORPCError } from '@orpc/server';
const handler = new OpenAPIHandler(router, {
interceptors: [
onError((error) => {
// Log the full error and stack trace
console.error('ORPC Internal Error:', error);
if (error instanceof ORPCError && error.cause) {
console.error('Underlying cause:', error.cause);
}
}),
],
});This will print the error and its stack trace to your server logs whenever an unhandled error occurs in a route handler. You can further customize the logging logic as needed. More details and examples are available in related discussions and issues and middleware docs. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Hi @evrys! I'm Dosu and I’m helping the orpc team.
You can log underlying errors and stack traces in ORPC by adding custom error handling middleware or using the
onErrorinterceptor when setting up yourOpenAPIHandler. By default, ORPC hides error details for security, but you can intercept errors and log them before they're sent to the client.Here's a pattern you can use: