Chuyển tới nội dung chính

Error Classes

All SDK errors extend FaosError, which extends the native Error class.

import {
FaosError,
ShortcutError,
ShortcutNotFoundError,
ShortcutRateLimitError,
} from '@faos/sdk';

Error Hierarchy

Error
└── FaosError
└── ShortcutError
├── ShortcutNotFoundError
└── ShortcutRateLimitError

FaosError

Base error for all FAOS SDK errors.

try {
const response = await client.shortcut('invalid');
} catch (err) {
if (err instanceof FaosError) {
console.error(`FAOS error: ${err.message}`);
}
}

ShortcutError

Base error for shortcut operations. Extends FaosError.

ShortcutNotFoundError

Thrown when a shortcut command cannot be resolved.

PropertyTypeDescription
commandstringThe shortcut command that was not found
suggestionsstring[]Similar shortcuts the user may have intended
import { ShortcutNotFoundError } from '@faos/sdk';

try {
await client.shortcut('bnk credit-analyst');
} catch (err) {
if (err instanceof ShortcutNotFoundError) {
console.log(`Unknown: ${err.command}`);
console.log(`Did you mean: ${err.suggestions.join(', ')}`);
// Output: Unknown: bnk credit-analyst
// Output: Did you mean: bank credit-analyst
}
}

ShortcutRateLimitError

Thrown when API rate limit is exceeded.

PropertyTypeDescription
retryAfternumber | nullSeconds to wait before retrying
import { ShortcutRateLimitError } from '@faos/sdk';

try {
await client.shortcut('bank credit-analyst');
} catch (err) {
if (err instanceof ShortcutRateLimitError) {
if (err.retryAfter) {
await new Promise((r) => setTimeout(r, err.retryAfter! * 1000));
await client.shortcut('bank credit-analyst');
}
}
}