Errors
All domain failures share a common base so you can write one catch path for the SDK.
Base class
Section titled “Base class”class MobileLockerError extends Error { readonly code: string constructor(message: string, code?: string) // default code: server_error}import { MobileLockerError, MobileLockerCRMError, MobileLockerDatabaseError, MobileLockerHTTPError, MobileLockerHttpResponseError, GeneralErrorCode, CRMErrorCode, DatabaseErrorCode, HTTPErrorCode,} from '@mobilelocker/javascript-sdk'
try { await mobilelocker.crm.query('SELECT Id FROM Account')} catch (err) { if (err instanceof MobileLockerError) { console.error(err.code, err.message)
if (err.code === GeneralErrorCode.NotConnected) { showOfflineBanner() return }
if (err instanceof MobileLockerCRMError) { if (err.code === CRMErrorCode.AuthExpired) { promptReauth() return } if (err.code === CRMErrorCode.SOQLInvalid) { console.error('Fix the query', err.crmMessage) return } } } throw err}instanceof MobileLockerError is true for CRM, database, and HTTP error subclasses.
Error classes
Section titled “Error classes”| Class | Thrown by | Extra fields |
|---|---|---|
MobileLockerError |
General SDK failures | code |
MobileLockerCRMError |
crm.* |
code: CRMErrorCode, crmMessage?: string |
MobileLockerDatabaseError |
database.* |
code: DatabaseErrorCode, sqliteMessage?: string |
MobileLockerHTTPError |
http.* transport (timeout, offline, …) |
code: HTTPErrorCode |
MobileLockerHttpResponseError |
http.* non-2xx responses |
status, statusText, headers, data (code is server_error) |
Code constants
Section titled “Code constants”Prefer constants over raw strings. CRM / Database / HTTP constants spread general codes.
GeneralErrorCode
Section titled “GeneralErrorCode”| Constant | Code string |
|---|---|
NotConnected |
not_connected |
ServerError |
server_error |
RequestTimeout |
request_timeout |
InvalidArgument |
invalid_argument |
UnsupportedEnvironment |
unsupported_environment |
NotFound |
not_found |
CRMErrorCode (includes all general +)
Section titled “CRMErrorCode (includes all general +)”| Constant | Code string |
|---|---|
NotSupported |
crm_not_supported |
AuthExpired |
crm_auth_expired |
SOQLInvalid |
soql_invalid |
DatabaseErrorCode (includes all general +)
Section titled “DatabaseErrorCode (includes all general +)”| Constant | Code string |
|---|---|
NotReady |
databases_not_ready |
InvalidPath |
invalid_database_path |
WriteNotPermitted |
write_not_permitted |
QueryFailed |
query_failed |
HTTPErrorCode
Section titled “HTTPErrorCode”Same set as GeneralErrorCode (no additional codes).
Status objects (not thrown)
Section titled “Status objects (not thrown)”Some APIs return status unions with withStatusBooleans helpers instead of throwing:
| API | status values |
Boolean helpers |
|---|---|---|
scanner.scan* |
success | cancelled | failed |
isSuccess, isCancelled, isFailed |
crm.openCustomerPicker |
selected | cancelled |
isSelected, isCancelled |
crm.refresh |
started | not_connected |
isStarted, isNotConnected |
presentation.download |
queued | already_installed | not_available | not_permitted |
isQueued, isAlreadyInstalled, … |
ui.openVideo |
completed | dismissed | failed |
isCompleted, isDismissed, isFailed |
Snake_case statuses become camelCase booleans (not_connected → isNotConnected).
const result = await mobilelocker.scanner.scanBusinessCard()if (result.isSuccess) { /* … */ }if (result.status === 'cancelled') { /* … */ }Helper factories (advanced)
Section titled “Helper factories (advanced)”Exported for mappers / tests (usually not needed in presentation code):
mapToMobileLockerError·mapToCRMError·mapToDatabaseErrorunsupportedEnvironmentError(method, environment?)invalidArgumentError(message)
Logging errors
Section titled “Logging errors”mobilelocker.log.error('CRM failed', { code: err.code, message: err.message })const sdkLogs = await mobilelocker.log.getSdkLogs({ level: 'error', domain: 'crm' })