Skip to main content

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.
  • cause contains the original error. If the server rejected the request, err.cause.cause holds 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​

codeWhen
invalid_paramThe 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_tokenThe token content (payload) cannot be read
not_initializedCalled before init()
unauthorizedThe token is invalid. Reopening the learning material gets a new token
session_expiredThe token expired before a new token arrived, or the server ended the session. Tell the user to refresh
permission_deniedA request the token does not allow
read_only_modeA tutor submitted, or saved · deleted a kvstore value
screen_not_supportedA request not allowed on this screen (e.g. submit on the settings screen, saveSettings on a learning screen)
draft_not_savedsaveSettings · assets.post on the settings screen of an unsaved upload (#edit=1). Save the material first
content_not_readyThe material has no saved version yet, or saveSettings was rejected because the draft is being processed · failed
invalid_inputThe 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_limitedToo many submissions in a short time (30 per minute), or kvstore saves · deletes are too frequent (20 per second)
external_service_errorThe server failed at AI grading or recording the score. The submission was not saved, so submit again
navigation_timeoutThe learning page did not answer within 1 second whether there is a previous · next page
file_invalid_typeA file other than PDF · PPTX · PNG · JPEG · WebP · GIF passed to assets.post
file_invalid_sizeA file of 0 bytes or over the limit (documents 95MB · images 10MB) passed to assets.post
script_load_failedloadScript could not load the script
script_namespace_not_foundThe script loaded by loadScript did not create window[namespace]
storage_limit_exceededA kvstore save made my values in this material exceed 512KB
request_failedAny 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.