Skip to content

Error Handling

VeloxTS provides structured error handling with type-safe error responses.

import { NotFoundError, ValidationError, fail } from '@veloxts/core';
getUser: procedure()
.input(z.object({ id: z.string() }))
.query(async ({ input, ctx }) => {
const user = await ctx.db.user.findUnique({ where: { id: input.id } });
if (!user) {
throw new NotFoundError('User not found');
}
return user;
}),
ErrorStatusUse Case
ValidationError400Invalid input
NotFoundError404Resource not found
UnauthorizedError401Not authenticated
ForbiddenError403Not authorized
ConflictError409Resource conflict
import { VeloxError } from '@veloxts/core';
class PaymentError extends VeloxError {
constructor(message: string) {
super(message, 'PAYMENT_FAILED', 402);
}
}
{
"error": {
"message": "User not found",
"code": "NOT_FOUND"
}
}

VeloxTS uses structured error codes (E1xxx-E9xxx) with fix suggestions:

VeloxError[E1001]: Procedure "getUser" missing required input schema
Fix: Add .input() to your procedure definition