Skip to content

Errors

All domain failures share a common base so you can write one catch path for the SDK.

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.

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)

Prefer constants over raw strings. CRM / Database / HTTP constants spread general codes.

Constant Code string
NotConnected not_connected
ServerError server_error
RequestTimeout request_timeout
InvalidArgument invalid_argument
UnsupportedEnvironment unsupported_environment
NotFound not_found
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

Same set as GeneralErrorCode (no additional codes).

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_connectedisNotConnected).

const result = await mobilelocker.scanner.scanBusinessCard()
if (result.isSuccess) { /* … */ }
if (result.status === 'cancelled') { /* … */ }

Exported for mappers / tests (usually not needed in presentation code):

  • mapToMobileLockerError · mapToCRMError · mapToDatabaseError
  • unsupportedEnvironmentError(method, environment?)
  • invalidArgumentError(message)
mobilelocker.log.error('CRM failed', { code: err.code, message: err.message })
const sdkLogs = await mobilelocker.log.getSdkLogs({ level: 'error', domain: 'crm' })