Skip to content

Error Codes

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.

CodeNameUsage
200OKSuccessful GET, PUT, PATCH, DELETE
201CreatedSuccessful POST (resource created)
204No ContentSuccessful DELETE (no body)
CodeNameUsage
400Bad RequestInvalid input, validation failed
401UnauthorizedMissing or invalid authentication
403ForbiddenAuthenticated but not authorized
404Not FoundResource doesn’t exist
409ConflictResource already exists (e.g., duplicate email)
422Unprocessable EntitySemantic validation errors
429Too Many RequestsRate limit exceeded
CodeNameUsage
500Internal Server ErrorUnexpected server error
502Bad GatewayUpstream service error
503Service UnavailableServer overloaded or maintenance

Velox TS returns errors in a consistent format:

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
}
CodeHTTPDescription
VALIDATION_ERROR400Input validation failed
INVALID_INPUT400Malformed request body
MISSING_FIELD400Required field not provided
INVALID_FORMAT400Field format incorrect
CodeHTTPDescription
UNAUTHENTICATED401No valid auth token
TOKEN_EXPIRED401Access token expired
INVALID_TOKEN401Token malformed or invalid
REFRESH_TOKEN_EXPIRED401Refresh token expired
SESSION_EXPIRED401Session no longer valid
CodeHTTPDescription
FORBIDDEN403Action not permitted
INSUFFICIENT_PERMISSIONS403Missing required permission
ROLE_REQUIRED403Missing required role
CodeHTTPDescription
NOT_FOUND404Resource doesn’t exist
ALREADY_EXISTS409Duplicate resource
CONFLICT409State conflict
CodeHTTPDescription
RATE_LIMITED429Too many requests
QUOTA_EXCEEDED429Usage 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({
where: { id: input.id },
});
if (!user) {
throw new TRPCError({
code: 'NOT_FOUND',
message: 'User not found',
});
}
return user;
});
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';
try {
const user = await client.users.getUser.query({ id: '123' });
} catch (error) {
if (error.data?.code === 'NOT_FOUND') {
// Handle not found
} else if (error.data?.code === 'UNAUTHENTICATED') {
// Redirect to login
}
}

Velox TS uses tRPC error codes internally:

tRPC CodeHTTPDescription
BAD_REQUEST400Invalid request
UNAUTHORIZED401Not authenticated
FORBIDDEN403Not authorized
NOT_FOUND404Resource not found
CONFLICT409Resource conflict
PARSE_ERROR400JSON parse error
INTERNAL_SERVER_ERROR500Server error