TypeScript SDK
Handle SDK responses
Inspect typed success and error results from @orvelt/business operations.
Inspect the result form
Check errors before data
SDK operations return { data, error, request, response } by default. Check error before reading data:
Inspect a typed list response before reading its data.
import { opinions } from '@orvelt/business';
const result = await opinions.list({
projectId: 'PROJECT_ID',
page: 1,
limit: 25,
responseStatus: 'unresponded',
});
if (result.error) {
console.error(result.response.status, result.error.code, result.error.message);
return;
}
for (const opinion of result.data.opinions) {
console.log(opinion);
}curl --request GET \\
--url "$ORVELT_API_BASE_URL/project/PROJECT_ID/opinions?page=1&limit=25&responseStatus=unresponded" \\
--header "x-api-key: $ORVELT_BUSINESS_API_KEY"Treat validation failures as errors
The generated client validates successful responses with Zod. A response that does not match the contract becomes an error instead of silently producing an untyped object.
Throw on errors
Use one exception boundary
Set throwOnError: true in the client configuration when your service handles API failures in one boundary:
Configure thrown errors for one request boundary.
import { orvelt, goals } from '@orvelt/business';
orvelt({
apiKey: process.env.ORVELT_BUSINESS_API_KEY!,
throwOnError: true,
});
try {
const result = await goals.list({
projectId: 'PROJECT_ID',
});
console.log(result.data);
} catch (error) {
console.error('Business API request failed', error);
}curl --request GET \\
--url "$ORVELT_API_BASE_URL/project/PROJECT_ID/goals" \\
--header "x-api-key: $ORVELT_BUSINESS_API_KEY"Keep status-specific handling explicit
Use the default result form when a route needs to distinguish 401, 403, 404, 409, 429, and 503 outcomes. See Errors for recovery guidance.