Skip to main content

Errors

Every non-2xx response from the DhivehiGPT API is thrown as an error. All error classes extend the base DhivehiGPTError, so you can always catch that as a fallback.

import { DhivehiGPTError } from '@javaabu/dhivehigpt-sdk';

try {
await client.tts.generate({ text: '...', voice: 'unknown-voice' });
} catch (error) {
if (error instanceof DhivehiGPTError) {
console.log(error.status, error.message, error.body);
}
}

Error classes

ClassHTTP statusThrown when
AuthenticationError401The X-Api-Key header is missing, invalid, or has been revoked.
InsufficientCreditsError403The API key's team doesn't have enough credits to complete the request.
NotFoundError404The requested resource doesn't exist, or doesn't belong to your team.
ValidationError422The request body or parameters failed validation.
RateLimitError429The API key has exceeded 60 requests per minute.
ServerError5xxAn unexpected error occurred upstream (e.g. the speech provider failed).
DhivehiGPTErroranyBase class for all of the above; also used for any unmapped status code.

Properties

Every error exposes:

  • status: number — the HTTP status code.
  • message: string — the API's error message.
  • body: { message: string; errors?: Record<string, string[]> } | undefined — the raw parsed response body.

ValidationError additionally exposes an errors getter with field-level validation messages:

import { ValidationError } from '@javaabu/dhivehigpt-sdk';

try {
await client.tasks.calculate({ task: 'not-a-real-task', units: 10 });
} catch (error) {
if (error instanceof ValidationError) {
console.log(error.errors); // { task: ['The selected task is invalid.'] }
}
}