Error handling
Errors thrown by the SDK are EliceCDKErrors, distinguished by code. The exception is the AggregateError thrown when init() cannot read the fragment (see below).
import { EliceCDKError } from '@eliceio/cdk';
try {
await sdk.submit(answer);
} catch (err) {
if (err.code === EliceCDKError.code.ReadOnlyMode) {
// 튜터 화면: 제출 버튼을 숨김
}
}
- Use code constants like
EliceCDKError.code.ReadOnlyMode. Their values are the strings in the table below. causecontains the original error. If the server rejected the request,err.cause.causeholds the server response{ code, message, status, detail }.
AggregateError from init()
If the fragment contains none of token · preview · edit, the token is not in JWT format, or versionId is not a UUID, init() throws an AggregateError. Its errors array contains one EliceCDKError with the invalid_param code per problem.
try {
await sdk.init();
} catch (err) {
const errors = err instanceof AggregateError ? err.errors : [err];
console.error(errors.map(e => e.code));
}
When init() fails, LXP shows a failure screen, so the content usually only needs to log it.
Error codes
| code | When |
|---|---|
invalid_param | The URL has no token or material information (for init(), inside an AggregateError), versionId is not a saved version of that material, or the kvstore key format is invalid |
invalid_token | The token content (payload) cannot be read |
not_initialized | Called before init() |
unauthorized | The token is invalid. Reopening the learning material gets a new token |
session_expired | The token expired before a new token arrived, or the server ended the session. Tell the user to refresh |
permission_denied | A request the token does not allow |
read_only_mode | A tutor submitted, or saved · deleted a kvstore value |
screen_not_supported | A request not allowed on this screen (e.g. submit on the settings screen, saveSettings on a learning screen) |
draft_not_saved | saveSettings · assets.post on the settings screen of an unsaved upload (#edit=1). Save the material first |
content_not_ready | The material has no saved version yet, or saveSettings was rejected because the draft is being processed · failed |
invalid_input | The request was rejected, e.g. an answer over 64KB, or a value in the middle of a kvstore key path is not an object |
rate_limited | Too many submissions in a short time (30 per minute), or kvstore saves · deletes are too frequent (20 per second) |
external_service_error | The server failed at AI grading or recording the score. The submission was not saved, so submit again |
navigation_timeout | The learning page did not answer within 1 second whether there is a previous · next page |
file_invalid_type | A file other than PDF · PPTX · PNG · JPEG · WebP · GIF passed to assets.post |
file_invalid_size | A file of 0 bytes or over the limit (documents 95MB · images 10MB) passed to assets.post |
script_load_failed | loadScript could not load the script |
script_namespace_not_found | The script loaded by loadScript did not create window[namespace] |
storage_limit_exceeded | A kvstore save made my values in this material exceed 512KB |
request_failed | Any other failure. The server code is in err.cause.cause.code |
sdk.mlapi.fetch returns the response as is, so server errors also arrive as responses. See AI calls.