refactor: improve error handling in captureErrorsMiddleware (#20718)

This commit is contained in:
Omar López
2025-04-16 14:01:47 +00:00
committed by GitHub
parent 5972a6f77f
commit ddfd3fda70
@@ -5,16 +5,15 @@ import { redactError } from "@calcom/lib/redactError";
import { middleware } from "../trpc";
const captureErrorsMiddleware = middleware(async ({ next }) => {
const result = await next();
if (result && !result.ok) {
const cause = result.error.cause;
if (!cause) {
return result;
}
captureException(cause);
throw redactError(cause);
try {
const result = await next();
if (result.ok) return result;
if (!result.error.cause) return result;
throw result.error.cause;
} catch (error) {
captureException(error);
throw redactError(error);
}
return result;
});
export default captureErrorsMiddleware;