Skip to content

Error Codes

Reference for error codes returned by VeloxTS APIs.

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

VeloxTS 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 { AppError } from '@veloxts/core';
// Throw domain-specific errors
throw new AppError('USER_NOT_FOUND', {
statusCode: 404,
message: 'User not found',
details: { userId: input.id },
});
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
}
}

VeloxTS 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