When something goes wrong, Velox TS returns structured error responses with HTTP status codes and machine-readable error codes. This reference covers every status code and error code your API can return, along with common causes and how to handle them on the client.
Code Name Usage 200OK Successful GET, PUT, PATCH, DELETE 201Created Successful POST (resource created) 204No Content Successful DELETE (no body)
Code Name Usage 400Bad Request Invalid input, validation failed 401Unauthorized Missing or invalid authentication 403Forbidden Authenticated but not authorized 404Not Found Resource doesn’t exist 409Conflict Resource already exists (e.g., duplicate email) 422Unprocessable Entity Semantic validation errors 429Too Many Requests Rate limit exceeded
Code Name Usage 500Internal Server Error Unexpected server error 502Bad Gateway Upstream service error 503Service Unavailable Server overloaded or maintenance
Velox TS returns errors in a consistent format:
"code" : " VALIDATION_ERROR " ,
"message" : " Validation failed " ,
"message" : " Invalid email format "
Code HTTP Description VALIDATION_ERROR400 Input validation failed INVALID_INPUT400 Malformed request body MISSING_FIELD400 Required field not provided INVALID_FORMAT400 Field format incorrect
Code HTTP Description UNAUTHENTICATED401 No valid auth token TOKEN_EXPIRED401 Access token expired INVALID_TOKEN401 Token malformed or invalid REFRESH_TOKEN_EXPIRED401 Refresh token expired SESSION_EXPIRED401 Session no longer valid
Code HTTP Description FORBIDDEN403 Action not permitted INSUFFICIENT_PERMISSIONS403 Missing required permission ROLE_REQUIRED403 Missing required role
Code HTTP Description NOT_FOUND404 Resource doesn’t exist ALREADY_EXISTS409 Duplicate resource CONFLICT409 State conflict
Code HTTP Description RATE_LIMITED429 Too many requests QUOTA_EXCEEDED429 Usage quota exceeded
import { TRPCError } from ' @trpc/server ' ;
export const getUser = procedure ()
. input (z . object ({ id: z . string () }))
. query ( async ( { input , ctx } ) => {
const user = await ctx . db . user . findUnique ( {
message: ' User not found ' ,
import { VeloxError, NotFoundError } from ' @veloxts/core ' ;
// Use built-in error classes for common cases
throw new NotFoundError ( ' User ' , input . id );
// Message: "User with id {id} not found"
// Or create custom domain errors
throw new VeloxError ( ' User account is suspended ' , 403 , ' USER_SUSPENDED ' );
import { client } from ' ./api ' ;
const user = await client . users . getUser . query ( { id: ' 123 ' } );
if (error . data ?. code === ' NOT_FOUND ' ) {
} else if (error . data ?. code === ' UNAUTHENTICATED ' ) {
Velox TS uses tRPC error codes internally:
tRPC Code HTTP Description BAD_REQUEST400 Invalid request UNAUTHORIZED401 Not authenticated FORBIDDEN403 Not authorized NOT_FOUND404 Resource not found CONFLICT409 Resource conflict PARSE_ERROR400 JSON parse error INTERNAL_SERVER_ERROR500 Server error